Sign in to follow this  
Followers 0
Docfxit

How to run a script with a user that is not logged on

11 posts in this topic

I need to run a script with a user that is not logged on to XP Pro sp2.

I'm logged into user Current. I have a remote machine that needs to run a script with user Remote.

This is the script: I did compile it.

#Include <File.au3>
#Include <Array.au3>
; Map X drive to \\myserver2\stuff2 using the user "jon" from "domainx" with password "tickle"
DriveMapAdd("L:", "\\myserver2\stuff", 0, "Remote", "Password")

$FileList=_FileListToArray("L:\","*.*",1)
If (Not IsArray($FileList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

; write array to file
_FileWriteFromArray("C:\SCRATCH\ListScansFiles.log", $FileList, 1)

; Disconnect
DriveMapDel("L:")

When I run it with the current user it runs fine. When I run it with the remote user it doesn't run.

How can I make it run with the remote user?

Thank You,

Docfxit

Share this post


Link to post
Share on other sites



Compile the script, then create another script and run the compiled version with RunAsSet(), or runas.exe from the command line.

Or, copy it to the remote PC, and use psexec or beyondexec, or a WMI Script, to execute it as that user.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I seem to be doing something wrong because it isn't working.

I have a remote computer that runs a Remote Procedure Call

Program to run c:\batch\scan.bat

User to run with = Remote

Password = Password (Correct password is used)

In Scan.bat I have:

Pause
runas /user:ATUUSER4\remote ScanFiles.exe

ScanFiles.exe is a compiled AutoIt script that looks like this:

#Include <File.au3>
#Include <Array.au3>
; Map X drive to \\myserver2\stuff2 using the user "jon" from "domainx" with password "tickle"
DriveMapAdd("L:", "\\myserver2\stuff", 0, "Remote", "Password")

    MsgBox (0,"","Read Files To Array")
$FileList=_FileListToArray("L:\","*.*",1)
If (Not IsArray($FileList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
; write array to file
_FileWriteFromArray("C:\SCRATCH\ListScansFiles.log", $FileList, 1)
; Disconnect
DriveMapDel("L:")

When I run Scan.bat from the logged in user I get

Pause (Which tells me the bat file is running)

It asks me for a password

Read Files To Array (Which tells me ScanFiles.exe is running)

And it produces the correct output (Which tells me it connected to the network drive)

When I run Scan.bat via the Remote Procedure Call from the other system I get nothing.

Any ideas why it won't run?

Thank you,

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I created a script to run with a different user.

Script name is ScanFiles.exe

$ReturnValue = RunAsSet('SCANS', @ComputerName, 'LETMEIN')
If $ReturnValue = 0 Then
    MsgBox(0, "Change User - " & @UserName, "@error - " & "The operating system does not support this function.")
EndIf
Run("ScanFiles2.exe", "C:\Batch")

When I run this with the user that is currently logged in (MyUser) It does run ScanFiles2.exe with the user Scans just fine.

When I run this with a user that is not logged in it does NOT run ScanFiles2.exe and it gives me an error saying:

Line -1

Error: Unable to execute the external program.

Access is denied.

ScanFiles.exe is running with user NT Authority/System

I have checked the security for the file ScanFiles2.exe. I changed it to have Everyone with Full Control

I have checked the security for C:\Batch. I changed it to have System, Scans, (Current User) with Full Control

How can I get the program to run?

Thank you,

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites

I created a script to run with a different user.

Script name is ScanFiles.exe

RunAsSet('SCANS', @ComputerName, 'password')
If @error = 0 Then
    MsgBox(0, "Change User - " & @UserName, "@error - " & "The operating system does not support this function.")
EndIf
Run("ScanFiles2.exe", "C:\Batch")
@error = 0 is normal. Most failures set @error to non-zero values. Try it with:
If @error Then
...or:
If @error <> 0 Then

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

@error = 0 is normal. Most failures set @error to non-zero values. Try it with:

If @error Then
...or:
If @error <> 0 Then

:)

Thank you for clearing that up. I made a mistake when reading the help file. It does say Return Value returns a 0 when it fails.

I have corrected my post. Now if someone could only figure out the Access denied error I'd be in better shape.

Thank you,

Docfxit

Share this post


Link to post
Share on other sites

I'm getting an error when I run this code. The error I am getting is:

@error - 1

@extended - 1312

What is this error? I can't find it anyplace.

Thank you,

Docfxit

#Include <File.au3>

    DriveMapAdd("L:", "\\ATU1277\Scans", 0, "SCANS", "password")
    If @ERROR <> 0  Then
    MsgBox(0, "Error Mapping Drive", "@error - " & @error & @CRLF & "@extended - " & @extended)
    EndIf
    $FileList = _FileListToArray("L:\", "*.*", 1)
    If (Not IsArray($FileList)) And (@error = 1) Then
        MsgBox(0, "", "No Files\Folders Found.")
        Exit
    EndIf
    ; write array to file
    _FileWriteFromArray("C:\Dnload\AutoIt\ListScansFiles.log", $FileList, 1)
        MsgBox(0, "", "All Done")
    ; Disconnect
    DriveMapDel("L:")

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I'm getting an error when I run this code. The error I am getting is:

@error - 1

@extended - 1312

What is this error? I can't find it anyplace.

Thank you,

Docfxit

#Include <File.au3>

    DriveMapAdd("L:", "\\ATU1277\Scans", 0, "SCANS", "password")
    If @ERROR <> 0  Then
    MsgBox(0, "Error Mapping Drive", "@error - " & @error & @CRLF & "@extended - " & @extended)
    EndIf
    $FileList = _FileListToArray("L:\", "*.*", 1)
    If (Not IsArray($FileList)) And (@error = 1) Then
        MsgBox(0, "", "No Files\Folders Found.")
        Exit
    EndIf
; write array to file
    _FileWriteFromArray("C:\Dnload\AutoIt\ListScansFiles.log", $FileList, 1)
        MsgBox(0, "", "All Done")
; Disconnect
    DriveMapDel("L:")
I hacked this together from the code for _WinAPI_GetLastErrorMessage() in WinAPI.au3. Might be fun to try:
#include <WinAPI.au3>

Global $iErrSav = 0, $iExtSav = 0
Global $tText = DllStructCreate("char Text[4096]")
Global $pText = DllStructGetPtr($tText), $sMessage = "<None>"

DriveMapAdd("L:", "\\ATU1277\Scans", 0, "SCANS", "password")
$iErrSav = @error
$iExtSav = @extended
If $iErrSav <> 0 Then
    If $iErrSav = 1 Then
        _WinAPI_FormatMessage($FORMAT_MESSAGE_FROM_SYSTEM, 0, $iExtSav, 0, $pText, 4096, 0)
        $sMessage = DllStructGetData($tText, "Text")
    EndIf
    MsgBox(0, "Error Mapping Drive", "@error = " & $iErrSav & @CRLF & _
            "@extended = " & $iExtSav & @CRLF & _
            "Message = " & $sMessage)
EndIf

If you get a chance to try it, please post the resulting message. When I run this, knowing the path, username, and password are all bogus, I get:

@error = 1
@extended = 53
Message = The network path was not found.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thank you for the script.

When I run it I get:

@error = 1

@extended = 1312

Message = A specified logon session does not exist. It may already have been terminated.

I'm wondering if this is a timing issue. When I connect to the network drive locally it does take a long time to connect.

I'm wondering if AutoIt doesn't wait long enough.

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites

Thank you for the script.

When I run it I get:

@error = 1

@extended = 1312

Message = A specified logon session does not exist. It may already have been terminated.

Docfxit

Try adding the Domain or ComputerName context to the username, i.e.:
DriveMapAdd("L:", "\\ATU1277\Scans", 0, "ATU1277\SCANS", "password"); Local account on remote computer
DriveMapAdd("L:", "\\ATU1277\Scans", 0, "MyDomain\SCANS", "password"); Domain account

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Try adding the Domain or ComputerName context to the username, i.e.:

DriveMapAdd("L:", "\\ATU1277\Scans", 0, "ATU1277\SCANS", "password"); Local account on remote computer
DriveMapAdd("L:", "\\ATU1277\Scans", 0, "MyDomain\SCANS", "password"); Domain account

:)

I added the Local account. I'm connected with a workgroup.

It works. I posted the error without changing the password.

That fixed it. You are really great. I can't thank you enough. :-)

Thanks,

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0