Jump to content

Add function value to CMD path


Recommended Posts

Hi all,

 

I am trying to write a script which will run an elevated cmd and runs a specific program under a regular user profile (domain environment).

The program must be run under the logged in user's profile.

I found this code to obtain the logged in username in the elevated cmd:

Func _GetUsername()
    Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", "int", 0, "dword", -1, "int", 5, "dword*", 0, "dword*", 0)
    If @error Or $aResult[0] = 0 Then Return SetError(1, 0, 0)
    Local $sUsername = BinaryToString(DllStructGetData(DllStructCreate("byte[" & $aResult[5] & "]", $aResult[4]), 1), 2)
    DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $aResult[4])
    Return $sUsername
EndFunc

And this is how I run the elevated cmd:

When I try to add the full path to the MsgBox command (just to test if I get the full path), it will only display the path ending with the username:

MsgBox(1, "", "C:\users\" & _GetUsername() & "\Appdata\Roaming\Microsoft")

Output: C:\users\loggedinusername

 

I tried several similar solutions but can't get anything to display after the _GetUsername() func.

What I want to achieve:

Run a program located in the logged in user's Appdata folder, which requires elevation.

The %userprofile% parameter will give the administrator's username, that's why I need this _GetUsername() part.

Do you have any idea what I am doing wrong/missing?

Thank you.

 

 

Best regards

tciAgnt

 

 

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...