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";
}
}
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";
}
}