Perl - Windows Service to Map Drive

Discussion in 'Perl Misc' started by John Ferrell, Oct 1, 2003.

  1. John Ferrell

    John Ferrell Guest

    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 => "\\\\\\logs"
    $User = "cjones";
    $Password = "cj0n3s~";
    Win32::NetResource::AddConnection( \%NetResource, $Password, $User, 0

    #copy file
    copy("c:\\program files\\pwrchute\\$hostname.log",
    "v:\\$hostname.log") or die "file copy failed\n";
    John Ferrell, Oct 1, 2003
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page