Net use in batch does not work in task Scheduler

Discussion in 'Windows Server' started by monalude, Mar 16, 2005.

  1. monalude

    monalude Guest

    I am attempting to run a batch file that requires two network drives to be
    mapped. If i run the batch file manually it works fine. Running it through
    schedular the drives do not get mapped and I am using a system administrator
    account...Any ideas..or explanations why net use fails.

    Thank You ahead of time
     
    monalude, Mar 16, 2005
    #1
    1. Advertisements

  2. Add some diagnostics and you'll soon see why:

    @echo off
    echo %date% %time% %UserName% > c:\netuse.txt
    net use x: \\YourServer\YourShare 1>>c:\netuse.txt 2>c:\netuse.err
     
    Pegasus \(MVP\), Mar 16, 2005
    #2
    1. Advertisements

  3. monalude

    chieko Guest

    Did you add the administrator account to the "log on as a batch job" in the
    Local Security Settings under User Rights Assignment?
    I guess I mapped drives the hard way... using an exe file:

    ' in the header add...
    Const RESOURCETYPE_DISK = &H1
    Private Type NETRESOURCE
    dwScope As Long
    dwType As Long
    dwDisplayType As Long
    dwUsage As Long
    lpLocalName As String
    lpRemoteName As String
    lpComment As String
    lpProvider As String
    End Type
    Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
    "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As
    String, ByVal lpUsername As String, ByVal dwFlags As Long) As Long
    Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias
    "WNetCancelConnection2A" (ByVal lpname As String, ByVal dwFlags As Long,
    ByVal fForce As Long) As Long
    Dim theNetResource As NETRESOURCE
    Dim UserName As String
    Dim UserPassword As String

    ' on load a form...
    'open a connection to the remote database called databases.
    ' \\unch-main1\databases\hobo\hobo.mdb
    theNetResource.lpRemoteName = "\\unch-main1\databases"
    theNetResource.lpLocalName = "L:"
    UserName = "domain\username"
    UserPassword = "mypassword"
    theNetResource.dwType = RESOURCETYPE_DISK
    Label1.Caption = ""
    Command1.Caption = "Add Connection"
    Command2.Caption = "Cancel Connection"

    ' add the connection

    Dim Result&
    Result = WNetAddConnection2(theNetResource, UserPassword, UserName, 0)

    If Result = 0 Then
    Label1.Caption = "Connection Established."
    'Drive1.Drive = theNetResource.lpLocalName
    'Drive1.Refresh
    Else
    Label1.Caption = "Connection not possible."
    MsgBox "Connection not possible." & vbCrLf & "(Maybe the drive is
    allready used or the share doesn't exist)"
    End If



    chieko
     
    chieko, Mar 21, 2005
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.