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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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.
Answered 11/27/2011 by: mahendraKumar
Senior Yellow Belt

Please log in to comment
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
Answered 11/28/2011 by: weberik
Yellow Belt

Please log in to comment
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.
Answered 11/28/2011 by: virtualize
Orange Senior Belt

Please log in to comment
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%)

Answered 11/28/2011 by: weberik
Yellow Belt

Please log in to comment
0
Why you guys wanna go thru all this rigamarole? just use the property [LogonUser]
Answered 11/28/2011 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
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)
Answered 11/28/2011 by: weberik
Yellow Belt

Please log in to comment
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.
Answered 12/05/2011 by: virtualize
Orange Senior Belt

Please log in to comment
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
Answered 12/05/2011 by: weberik
Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity