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 => "\\\\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";
    }
    }
     
    John Ferrell, Oct 1, 2003
    #1
    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.
Similar Threads
  1. Jon
    Replies:
    5
    Views:
    12,138
    Scott M.
    Jan 17, 2010
  2. mh
    Replies:
    4
    Views:
    893
    Wolfgang Strobl
    May 31, 2005
  3. Tom Anderson
    Replies:
    8
    Views:
    582
    Gerrit Holl
    Sep 15, 2005
  4. Mike Joyce
    Replies:
    3
    Views:
    3,419
    Gordon Rainsford
    May 3, 2006
  5. shailesh
    Replies:
    1
    Views:
    1,060
    Tim Golden
    Mar 28, 2007
  6. deliasmith

    C DRIVE AND D DRIVE

    deliasmith, May 16, 2008, in forum: ASP .Net
    Replies:
    16
    Views:
    3,087
  7. lar
    Replies:
    0
    Views:
    327
  8. king
    Replies:
    1
    Views:
    458
Loading...