Jump to content

Permissions issues with FileExists


cshbell
 Share

Recommended Posts

I'm creating a script that will be run by users with Administrator privileges:

RunAsSet("Administrator", "DOMAIN", "password")
If FileExists("C:\WINDOWS\$NtUninstallKB917013$\spuninst\spuninst.exe") Then
Run("C:\WINDOWS\$NtUninstallKB917013$\spuninst\spuninst.exe /q /norestart")
EndIf
RunAsSet()

I only want it to trigger if the package is actually on the computer, hence the If FileExists. however, the file that I need to use for determining whether or not the package is installed (spuninst.exe) is in a location that a user without Administrator privileges does not have access to. Therefore, the If FileExists assertion fails, because (I assume) the If FileExists is being executed with the user's default privileges and not the escalated privileges used by RunAsSet.

So my question is, is there a way to perform the If FileExists check with escalated (e.g. Administrator-level) privileges?

Link to comment
Share on other sites

I'm creating a script that will be run by users with Administrator privileges:

RunAsSet("Administrator", "DOMAIN", "password")
If FileExists("C:\WINDOWS\$NtUninstallKB917013$\spuninst\spuninst.exe") Then
Run("C:\WINDOWS\$NtUninstallKB917013$\spuninst\spuninst.exe /q /norestart")
EndIf
RunAsSet()

I only want it to trigger if the package is actually on the computer, hence the If FileExists. however, the file that I need to use for determining whether or not the package is installed (spuninst.exe) is in a location that a user without Administrator privileges does not have access to. Therefore, the If FileExists assertion fails, because (I assume) the If FileExists is being executed with the user's default privileges and not the escalated privileges used by RunAsSet.

So my question is, is there a way to perform the If FileExists check with escalated (e.g. Administrator-level) privileges?

One quick way:

Opt("RunErrorsFatal", 0)

RunAsSet("Administrator", "DOMAIN", "password")
$RET = RunWait(@ComSpec & ' /c DIR "C:\WINDOWS\$NtUninstallKB917013$\spuninst\spuninst.exe"')
If ($RET = 0) And @error = 0 Then
    Run("C:\WINDOWS\$NtUninstallKB917013$\spuninst\spuninst.exe /q /norestart")
EndIf
RunAsSet()

:P

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...