Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

need vb script to be perl

by JFarr (Sexton)
on Feb 01, 2007 at 19:59 UTC ( #597808=perlquestion: print w/replies, xml ) Need Help??

JFarr has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I've created this VBscript, and it works as expected.
But now I need it to be in perl and I am having trouble
with some of the Win32::OLE calls, so any help would be
appreciated.
In the code below, I need to connect to a server with my admin rights, then create a scheduled task. Which this vb script does.
In my perl attempts it breaks at the
objNewJob.Create("C:\Rescue21\install\fixsnmp.bat", _ SchdTime, False , , , , JobID)

Set objLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objLocator.ConnectServer("es-g01-app01", "root\cim +v2", "NDRSMP\p57571", "Dragon#06") Set colItems = objWMIService.ExecQuery(wmiQuery) wscript.echo "Now establish a scheduled task" Set objNewJob = objWMIService.Get("Win32_ScheduledJob") set objTZone = objWMIService.ExecQuery("Select Bias From Win32_TimeZon +e") for each objItem in objTZone strBias = objItem.Bias Next SchdTime = TimeConvert(time, strBias) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate, (Sec +urity)}!\\" _ & "es-g01-app01" & "\root\cimv2") Set objNewJob = objWMIService.Get("Win32_ScheduledJob") errJobCreated = objNewJob.Create("C:\Rescue21\install\fixsnmp.bat", _ SchdTime, False , , , , JobID)
I'd rather be racing my Daytona

Replies are listed 'Best First'.
Re: need vb script to be perl
by GrandFather (Saint) on Feb 01, 2007 at 20:41 UTC

    Posting the original working VB is fine, but what does your Perl look like? I'd expect something a little like:

    my $objLocator = CreateObject("WbemScripting->SWbemLocator"); my $objWMIService = $objLocator->ConnectServer("es-g01-app01", "root\\ +cimv2", "NDRSMP\\p57571", "Dragon#06"); my $colItems = objWMIService->ExecQuery($wmiQuery); print ("Now establish a scheduled task"); my $objNewJob = objWMIService->Get("Win32_ScheduledJob"); my @objTZone = objWMIService->ExecQuery("Select Bias From Win32_TimeZo +ne"); $strBias = $_->Bias for @objTZone; my $SchdTime = TimeConvert(time, $strBias); $objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate, (Security)}!\\es-g01-ap +p01\root\cimv2" ); $objNewJob = objWMIService->Get("Win32_ScheduledJob"); my $errJobCreated = $objNewJob->Create("C:\\Rescue21\\install\\fixsnmp +->bat", SchdTime, False , undef, undef, undef, JobID);

    DWIM is Perl's answer to Gödel
      ...1\\install\\fixsnmp->bat", SchdTime, Fa...

      ;-)

      s/\./->/g once too often.

        'something like' I said, not exactly like. A global search and replace happened and not all the spurious replaces got fixed :-D.


        DWIM is Perl's answer to Gödel
Re: need vb script to be perl
by roboticus (Chancellor) on Feb 02, 2007 at 03:13 UTC
    JFarr:

    Ummmm ... If you have a working program, why do you need to convert it to Perl?

    I'm not trying to be flippant, I'm just a believer in "Don't Repeat Yourself".

    --roboticus

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://597808]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2023-05-31 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?