Sign in to follow this  
Followers 0
JayMan

Strange problem with UNC paths & Run()

5 posts in this topic

Just trying to learn AutoIT here... So please go easy on me lol

I'm writting a test script to see if i can get AutoIT functioning how i'd like...

Basically i want it to check for admin rights, if the user isn't an admin, then re-run the script using an account with admin rights... I've pretty much got it all working, but I can't get past 1 small thing...

Running the file locally, works 100% as expected... Running from a mapped drive, introduced the problem of the elevated user not having any mappings, so hence could re-run the script... Added some script to check for running on a mapped drive, and if so, work out the UNC path instead, then re-run using the UNC path... This is were it gets weird...

Running from a mapped drive (e.g. F:\script.exe, where F:\ is mapped to \\server\location), fails... Running the very same script from a UNC path (i.e. \\server\location\script.exe) works successfully!

Any idea's on how I can get this working?

Thanks

JayMan

Share this post


Link to post
Share on other sites



@JayMan...Try this...

Run(@ComSpec & " /c " & 'F:\script.exe', "", @SW_HIDE)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The issue probably is that the workdir (the directory you start the program from) will not be available in the Run() command when using RunAsSet().

Just adding an available workdir to the Run() command will probably solve that.

Run("\\server\location\script.exe",@tempdir)
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is what i've got it running with at the moment...

Global $DriveUNC, $ExeUNC

;Convert the drive letter & path to UNC if not UNC already
if DriveMapGet(StringLeft(@AutoItExe, 2)) Then
;Convert drive letter to UNC
    $DriveUNC=DriveMapGet(StringLeft(@AutoItExe, 2))
;Creates full UNC path to Exe file
    $ExeUNC = $DriveUNC & StringTrimLeft(@AutoItExe, 2)
    MsgBox(0, "UNC Variables", "@AutoItExe = " & @AutoItExe & @CRLF & _ 
    "$DriveUNC = " & $DriveUNC & @CRLF & "$ExeUNC = " & $ExeUNC)
Else;Running from UNC so set $ExeUNC = @AutoItExe
    $ExeUNC = @AutoItExe
    MsgBox(0, "UNC Variables", "@AutoItExe = " & @AutoItExe & @CRLF & "$ExeUNC = " & $ExeUNC)
EndIf

;if user isn't admin, display info & restart as admin
If Not IsAdmin() Then
    MsgBox(0, "Message", "Current user (" & @UserName & ") does not have Admin Rights." & _
    @CRLF & "Resarting " & $ExeUNC & " with Admin Rights")
    RunAsSet("adminuser", @LogonDomain, "adminpassword")
    Run($ExeUNC)
    RunAsSet()
    Exit
EndIf

;display info to confirm user has changed
MsgBox(0, "Message", "Current User (" & @UserName & ") has Admin Rights.")

Exit

So u reckon replace Run($ExeUNC) with Run(@ComSpec & " /c " & $ExeUNC, "", @SW_HIDE)?

Edit: Just saw Jos' post... doh! That makes total sense now that ya mention it... I shall add in a working directory & see how it goes... (can't easily test at the moment since i'm at home... but i think that'd be it!) Thanks heaps Jos!

JayMan

Edited by JayMan

Share this post


Link to post
Share on other sites

AFAIK, scripts do not see mappings created by the user (for the user) and may need to map drives by the current script (for the current script). Upon elevation of user by the script, then mapping a drive may need to be done for it's own elevated use. So you may need to elevate first before mapping and using the drive. A UNC path will work if the path to the other PC is valid so is perhaps a better method to use if suitable.

:)

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