Sign in to follow this  
Followers 0
mcgill

RunAsSet not mapping drive

2 posts in this topic

I have a issue with AutoIt passing credentials when trying to map a network drive. If I have manually open up a cmd.exe with an admin account and map a drive it maps with no problems. If I do a RunAs on the AutoIt exe or do a RunAsSet within the application it does not map the drive. If I do a RunAsSet calling on cmd.exe, manually type in the command to connect the network drive it maps the network drive.......one issue, if I go to view the mapped drive through explorer its not mapped and if I reload a cmd.exe with admin credentials the drive is not mapped anymore. I can map drives fine with my regular account, just seems AutoIt is not passing the correct credentials when performing what I need. This does not make sense to me why its not working, a little help would be greatly appreciated, thanks

RUNASSET:

local $user = "username"

local $domain = @LogonDomain

local $passwd = "password"

RunAsSet($user, $domain, $passwd)

Run ("cmd.exe")

Also Tried:

local $user = "username"

local $domain = @LogonDomain

local $passwd = "password"

RunAsSet($user, $domain, $passwd)

Run (@comspec & " /c net use s: \\server\root", @WindowsDir, @SW_MINIMIZE)

Share this post


Link to post
Share on other sites



i...one issue, if I go to view the mapped drive through explorer its not mapped...

A script may need to create and manage it's own drive mapping. This is separate to a user drive mapping done through explorer.

RunAsSet() affects Run/RunWait functions so you can restart you script as admin, map the drive and do the rest of the process. Something like the below may help.

If DriveMapAdd('Z:', '\\server\root') Then
    ; Work with drive Z:
EndIf

Exit

Func OnAutoItStart()
    ; AutoRun "Script.exe" as Admin
    ; Add User name
    Local $user = 'username'
    ; Add Domain name
    Local $domain = @LogonDomain
    ; Add Password
    Local $password = 'password'
    ;
    ; Check incoming parameters
    If Not $CMDLINE[0] Then
        ; No parameters then restart as admin
        RunAsSet($user, $domain, $password)
        Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /admin')
        RunAsSet()
        Exit
    ElseIf $CMDLINE[1] <> '/admin' Then
        ; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc

:)

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