Sign in to follow this  
Followers 0
scottlong

RunAs program in network map drive

9 posts in this topic

I am beginner in AutoIT, I want to install a software in network server, but this program is not support UNC path,

so I must map a drive first (use DriveMapAdd), for example X: dirve.

RunAs($sUserName, $sDomain, $sPassword, 0, "X:\program")

but it does not work, who can tell me what's wrong with this?

Thanks a lot!

Share this post


Link to post
Share on other sites



Hi,

I guess you need to execute the exe on the remote machine. Try using psexec.

E.g. :http://www.autoitscript.com/forum/index.php?showtopic=66203

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

RunAs($sUserName, $sDomain, $sPassword, 0, "X:\program")

but it does not work, who can tell me what's wrong with this?

Thanks a lot!

It could be many reason why it won't work? Check the help file RunAs() remarks.

Remarks

Paths with spaces need to be enclosed in quotation marks.

It is important to specify a working directory the user you are running as has access to, otherwise the function will fail.

When running as an administrator, the Secondary Logon (RunAs) service must be enabled or this function will fail.

Also as a test I will open command prompt and type start x:\program see what message you will get. Must importan be sure the username has enough credential to run the x:\program.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks a lot for all of you kindly support first!

I need descript more clear for this problem.

First I map a drive X: via DriveMapAdd, due to the installation problem in network share folder,

this program is not support UNC path, like \\servername\sharename, so I must map network drive first.

then use following sentence,

RunAs($sUserName, $sDomain, $sPassword, 0, "X:\program"),

But the program did not start. If I changed X:\programto local path D:\program,

of cause, I copied all files to D drive already, it works fine.

So I want to know why RunAs does not work when program in mapping network drive?

Edited by scottlong

Share this post


Link to post
Share on other sites

Thanks a lot for all of you kindly support first!

I need descript more clear for this problem.

First I map a drive X: via DriveMapAdd, due to the installation problem in network share folder,

this program is not support UNC path, like \\servername\sharename, so I must map network drive first.

then use following sentence,

RunAs($sUserName, $sDomain, $sPassword, 0, "X:\program"),

But the program did not start. If I changed X:\program to local path D:\program,

of cause, I copied all files to D drive already, it works fine.

So I want to know why RunAs does not work when program in mapping network drive?

Who can give some hints about this problem?

I am sure the user with enough rights to access network drive program, also without spaces in program path and name.

Share this post


Link to post
Share on other sites

Thanks a lot for all of you kindly support first!

I need descript more clear for this problem.

First I map a drive X: via DriveMapAdd, due to the installation problem in network share folder,

this program is not support UNC path, like \\servername\sharename, so I must map network drive first.

then use following sentence,

RunAs($sUserName, $sDomain, $sPassword, 0, "X:\program"),

But the program did not start. If I changed X:\program to local path D:\program,

of cause, I copied all files to D drive already, it works fine.

So I want to know why RunAs does not work when program in mapping network drive?

Who can give some hints about this problem?

I am sure the user with enough rights to access network drive program, also without spaces in program path and name.

Share this post


Link to post
Share on other sites

I need descript more clear for this problem.

First I map a drive X: via DriveMapAdd, then use following sentence,

RunAs($sUserName, $sDomain, $sPassword, 0, "X:\program"),

But the program did not start. If I changed X:\programto local path D:\program,

of cause, I copied all files to D drive already, it works fine.

So I want to know why RunAs does not work when program in mapping network drive?

The problem is that your are mapping X: drive with the current user login account, but then you use RunAs() function to use the mapped share with a different user account. If you open command prompt and map a share, then map another share to the same server different credentials you get the following message "The network folder specified is currently mapped using a different user name and password."

Microsoft KB938120

Try running your entire script with RunAs(), add the lines below to the begging of your script:

$sUserName = 'Login Name'
$sPassword = 'Login Password'
$sDomain = 'The domain to authenticate against.'

If Not IsAdmin() Then
    RunAs($sUserName, $sDomain, $sPassword, 0, @AutoItExe, @SystemDir, @SW_HIDE)
    Exit
EndIf

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Thanks a lot! Now I know why program can not run in network map drive. ;)

Share this post


Link to post
Share on other sites

Hi, I found a way to do that from network locations:

You have to make two (2) different scripts with AutoIT:

1.- The first file must have the mapping to the network drive and the other actions like this:

#region ; Checking the drive Available
    Local $i
    Local $DriveLst = DriveGetDrive("ALL")
    Local $DriveLetter
    Local $AscDrive
    For $i = 1 to $DriveLst[0]
        $AscDrive = Asc($DriveLst[$i])
        If ($i < $DriveLst[0]) Then
            If (($AscDrive + 1) <> (Asc($DriveLst[$i + 1]))) Then
                $DriveLetter = StringUpper(Chr($AscDrive + 1))
                ExitLoop
            EndIf
        Else
            If (($AscDrive + 1) = (Asc($DriveLst[$i]) + 1)) Then
                $DriveLetter = Chr($AscDrive + 1)
                ExitLoop
            EndIf
        EndIf
    Next
#endregion
; End Checking the Drive Available
#region ; Mapping Network Drive
    $result = DriveMapAdd($DriveLetter & ":",  StringMid($installation_path, 1, StringLen($installation_path) - 1), 1)
    Local $errormsg = ""
    If (@extended > 0) Then
        $errormsg = _WinAPI_GetLastErrorMessage()
    EndIf
        Run($LogPath & ' "' & $Software_Name & '" "i" "Mapping Network Drive in ' & $DriveLetter & ':" "' & $result & ' - ERROR:' & @error & "-" & @extended & ' - ' & $errormsg & '"')
    If $result = 0 Then
        Exit
    EndIf
#endregion
; End Mapping Network Drive
#region ; Open the Program setup
    $result = Run('"' & $DriveLetter & ':\ProgramFolder\Setup.exe"', $DriveLetter & ":\ProgramFolder")
    $errormsg = _WinAPI_GetLastErrorMessage()
    Run($LogPath & ' "' & $Software_Name & '" "i" "Installing Sofware" "' & $result & ' - ERROR:' & @error & "-" & @extended & ' - ' & $errormsg & '"')
#endregion
; End Open the Program setup

--NOTE: Is very important to add the working dir in the run option:

$result = Run('"' & $DriveLetter & ':\ProgramFolder\Setup.exe"', $DriveLetter & ":\ProgramFolder") 

--Because is working with the network drive mapped.

2.- The other script, have the Administrative Credentials and run the other script, like this

#region ; Installing PDS
    $result = RunAsWait($UserName, $Domain, $PassWord, 1, '"' & $Server_Path & 'Network location\where the script\is located\script_1.exe"')
    Run($LogPath & ' "' & $Software_Name & '" "i" "Installing Script_1" "' & $result & '"')
#endregion
; End Installing PDS

And is working right now with my scripts.

I know this post is very old, but I figured out by myself and I hope it work for you guys.

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