Link to home
Start Free TrialLog in
Avatar of prologic08
prologic08

asked on

How to query the current logged in user using VBScript when running VBS under System account

We use SCCM to push out applications and updates to users. Regular staff are denied access to install any files as well as edit the registry. In SCCM, we have installs run under the System account which grants the accesses it needs to install programs. In my current case, I have a Batch file that does 2 things.. 1. install the application. 2. run a VBS that pulls the UserName and then creates a REG file that writes a bunch of lines as well as takes the username (objNetwork.UserName) and inputs it into one of the lines:
a.WriteLine("""HostName""=""IPC-" & objNetwork.UserName & """")

Open in new window

Then imports it into the Registry.

Here is the problem...because this all gets done under the System account in SCCM, the VBS thinks that the username is "System" so inputs it as system when it really should have been the logged in users name. I need to find a way to get the VBS to pull the actual user logged in. I was thinking that it can query the last logged in user which would obviously be the current user but I do not know how to code this. Any one have any ideas as to how I can make this work?

The actual code I am using is referenced in this previous post so I would be adding it to the code that I posted near the bottom:
https://www.experts-exchange.com/questions/28503825/Use-VBS-to-input-data-to-a-REG-file-and-run-it.html
ASKER CERTIFIED SOLUTION
Avatar of prologic08
prologic08

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aikimark
What does the environment variable hold?  If it is the actual user and not system, you should be able to use something like this:
Set oWshShell = wscript.CreateObject( “wscript.shell” )
strUserName = oWshShell.ExpandEnvironmentStrings( “%USERNAME%” )

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prologic08
prologic08

ASKER

On my machine the variable shows as SYSTEM.. My last comment above seemed to do the trick anyway so I would say I am good. Thanks for responding.
RobSampson, That gives me the same output as the code I posted so I can use either one.
Since I was able to find my own answer before Rob posted his, I am splitting it between the both of us since either will work.