/build/static/layout/Breadcrumb_cap_w.png

vbscript to check for the current user logged in

hello, i need a vb script that checks the current user logged in based on the loggin it needs check in the text file for the current user name and loggin id of te current user and write the value in the registry. Thanks

0 Comments   [ + ] Show comments

Answers (8)

Posted by: mahendraKumar 12 years ago
Senior Yellow Belt
0
Hi ,

Can you brief more about your task requirements.

U wanted to just check user logged on ?

where you wanted to write the same i meant abt the registry location.
Posted by: weberik 12 years ago
Yellow Belt
0
set winmgmts = GetObject("winmgmts:\\.\root\cimv2")
set items = winmgmts.ExecQuery("SELECT * from Win32_ComputerSystem",,48)
for each item in items
wsh.echo item.UserName
next
Posted by: virtualize 12 years ago
Orange Senior Belt
0
thanks for the instant reply........ I will brief step by step.... 1) first the script should check the current user who logged in i.e username. This we can do by checking the environemnt variable. 2) since the user name details will be saved in c:\temp\users.txt. I need to read this text line by line. 3) once i get the username details from the text i.e if strline = username then the details that is there in the line (for e.g (farst, ipord, 666666) here farst is username) then it should update in HKCU\user\farst nd and value should be ipord and 6666666. I hope i have shown u some clarity. Thanks once again fo responding.
Posted by: weberik 12 years ago
Yellow Belt
0
you can read the username from the evironment variable. but it returns the user name of the user running that process.
the script i posted tells you the logged on user.
this is usefull when your deployment tool (SCCM or similar) run the script itself with a special user (system or some service account).

im not writing a complete script for you. but i can provide you with a few snippets that might help you.
just put them all together and you have your script.


' read a text file and find a line beginning with some special string
Set fs = CreateObject("Scripting.FileSystemObject")
set file = fs.OpenTextFile("c:\temp\users.txt", 1)
do until file.AtEndOfStream
line = file.ReadLine
username = split(line, ",")(0)
if username = "myUser" then
regname = split(line, ",")(1)
regvalue = split(line, ",")(2)
exit do
end if
loop

' write a regkey
Set shell = WScript.CreateObject("WScript.Shell")
shell.RegWrite("HKLM\mykey\" & regname, regvalue)

' resolve environment vars
shell.ExpandEnvironmentStrings(%USERNAME%)

Posted by: aogilmor 12 years ago
9th Degree Black Belt
0
Why you guys wanna go thru all this rigamarole? just use the property [LogonUser]
Posted by: weberik 12 years ago
Yellow Belt
0
yes if you have an MSI. also it only gets the username of the user running the install itself.
also its about reading some file and using its content for regkey (looking like some kind of inventory)
Posted by: virtualize 12 years ago
Orange Senior Belt
0
Thanks weberik, it was a great script you have provided me.
its a great work on split function. It has worked for me.


Hey weberik, let me know how do you add the registry value into microsoft word using vb script.
Posted by: weberik 12 years ago
Yellow Belt
0
ORIGINAL: virtualize
.... how do you add the registry value into microsoft word using vb script.

what do you mean exactly?
sounds like you want to set the user initials
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ