Perl - Windows Service to Map Drive

J

John Ferrell

I am trying to write a Windows service using the Perl Dev Kit from
ActiveState, to map a network drive and copy a file to the mapped
drive at regular intervals.

The code I have works fine when I run the script from the command
prompt. However when I run it as a service the drive is not mapped.
I have tried to run the service using my account on the machine
instead of the system account, but cannot get that to work either.

Any suggestions would be greatly appreciated.

#!d:/perl/bin/perl.exe -w

package PerlSvc;
use File::Copy;
use Win32::NetResource;

our %Config;

$hostname = $ENV{'computername'};

sub Startup {
# here's where your startup code will go
while (ContinueRun(60)) {
# do some work here

#map the drive if need be
if (!-e "v:\\$hostname.log")
{
%NetResource = (
LocalName => "V:",
RemoteName => "\\\\129.2.112.15\\logs"
);
$User = "cjones";
$Password = "cj0n3s~";
Win32::NetResource::AddConnection( \%NetResource, $Password, $User, 0
);
}

#copy file
chomp($hostname);
copy("c:\\program files\\pwrchute\\$hostname.log",
"v:\\$hostname.log") or die "file copy failed\n";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top