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)
Please log in to answer
Posted by:
mahendraKumar
13 years ago
Posted by:
weberik
13 years ago
Posted by:
virtualize
13 years ago
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
13 years ago
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%)
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
13 years ago
Posted by:
weberik
13 years ago
Posted by:
virtualize
13 years ago
Posted by:
weberik
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.