Running Batch File as Current User

Hello,
I would like to know how can I run a batch file as the current logged on user.
TIA!

Youy need to use the override command using the runas=currentuser option

https://developer.bigfix.com/action-script/reference/execution/override.html

RunAs
Use this keyword to specify the user and the context to use when running the command specified in the action. Default value: agent

  • RunAs=agent applies the same process ownership characteristics as the current wait and run commands. The user and the context are the same as those used to with the current wait and run commands
  • RunAs=currentuser mimics RunAsCurrentUser.exe on Windows, using the same logic to identify the current user and similar code to create the process with an environment block sourced by the userToken. In case of multiple logged-on users, the BES agent chooses the console session if active, or the first logged-on user returned from the operating system.

Example
override wait
completion=job
hidden=true
runas=currentuser
wait __Download\patch.exe arg1 arg2 arg3

3 Likes

Thanks for the swift reply!

I tried adding the runascurrentuser but it didn’t work for me.

How would I add the context to this?

prefetch 1d03938688d5948b54d83e223ffee184aa665831 sha1:1d03938688d5948b54d83e223ffee184aa665831 size:181 http://IBM-BIGFIX.XXXXXX.co.il:52311/Uploads/1d03938688d5948b54d83e223ffee184aa665831/XTRABANNER.BAT.tmp sha256:31dd046ceb9c8949d716ce19205666358eb8965e25f4926398c0aed81444ef78
extract 1d03938688d5948b54d83e223ffee184aa665831
wait “{pathname of system folder & “\cmd.exe”}” /Q /C “{(pathname of client folder of current site) & “__Download\XTRABANNER.BAT”}”

prefetch 1d03938688d5948b54d83e223ffee184aa665831 sha1:1d03938688d5948b54d83e223ffee184aa665831 size:181 http://IBM-BIGFIX.XXXXXX.co.il:52311/Uploads/1d03938688d5948b54d83e223ffee184aa665831/XTRABANNER.BAT.tmp sha256:31dd046ceb9c8949d716ce19205666358eb8965e25f4926398c0aed81444ef78
extract 1d03938688d5948b54d83e223ffee184aa665831
override wait
completion=job
hidden=true
runas=currentuser
wait “{pathname of system folder & “\cmd.exe”}” /Q /C “{(pathname of client folder of current site) & “__Download\XTRABANNER.BAT”}”

Make sure there are no blank lines between the ‘override’ statement and the following ‘wait’

1 Like

If that one doesn’t work, it will probablay be due to the “ and ” smartquotes that you’d need to change to "

prefetch 1d03938688d5948b54d83e223ffee184aa665831 sha1:1d03938688d5948b54d83e223ffee184aa665831 size:181 http://IBM-BIGFIX.XXXXXX.co.il:52311/Uploads/1d03938688d5948b54d83e223ffee184aa665831/XTRABANNER.BAT.tmp sha256:31dd046ceb9c8949d716ce19205666358eb8965e25f4926398c0aed81444ef78
extract 1d03938688d5948b54d83e223ffee184aa665831
override wait
completion=job
hidden=true
runas=currentuser
wait "{pathname of system folder & "\cmd.exe"}" /Q /C "{(pathname of client folder of current site) & "__Download\XTRABANNER.BAT"}"

Also,a standard user account won’t be able to read our __BESData folder so you may need to copy the banner somewhere else first

3 Likes

For some reason it doesn’t work.
Exit code 1.

These are the commands in the batch file.

xcopy.exe \192.168.XX.XX\templates\xtrabanner c:\sig /e /i
C:\Windows\SysWOW64\REGSVR32 “C:\XTRABANNER Signature Preview Add-In\adxloader.dll” /s

Exit code 1 means no files were found to copy.

Your missing a double-slash before your IP address. It should be:

xcopy.exe \\192.168.XX.XX\templates\xtrabanner c:\sig /E /I

Here is a good simple manpage for the xcopy command for reference.

1 Like

So when ever I have needed to run a command / script as the user, I have put the script into c:\users\public.
The then the user can access the file and run it.
Hope this helps.

1 Like