Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i generate the system name, used id logged in and system OS in to a csv file by vb script?

Status
Not open for further replies.

singh0056

Technical User
Jul 12, 2015
3
IN
how can i generate the system name, used id logged in and system OS in to a csv file by vb script?
 
One way is to use a search engine to locate one of the many samples already written to do all the things you want, and then if you have problems, post your code and describe the problem, and someone will help.
 
You can retrieve system variables or execute commands, which shows you the desired results - for example:

sysvars.vbs
Code:
[COLOR=#804040][b]set[/b][/color] wshShell [COLOR=#804040][b]=[/b][/color] WScript[COLOR=#804040][b].[/b][/color][COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color] [COLOR=#ff00ff]"WScript.Shell"[/color] [COLOR=#804040][b])[/b][/color]

[COLOR=#0000ff]' retrieve system variables[/color]
computername [COLOR=#804040][b]=[/b][/color] wshShell[COLOR=#804040][b].[/b][/color]ExpandEnvironmentStrings[COLOR=#804040][b]([/b][/color] [COLOR=#ff00ff]"%COMPUTERNAME%"[/color] [COLOR=#804040][b])[/b][/color]
os [COLOR=#804040][b]=[/b][/color] wshShell[COLOR=#804040][b].[/b][/color]ExpandEnvironmentStrings[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"%OS%"[/color][COLOR=#804040][b])[/b][/color]
username [COLOR=#804040][b]=[/b][/color] wshShell[COLOR=#804040][b].[/b][/color]ExpandEnvironmentStrings[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"%USERNAME%"[/color][COLOR=#804040][b])[/b][/color]

[COLOR=#0000ff]' execute command and get the output[/color]
[COLOR=#804040][b]set[/b][/color] get_os_version [COLOR=#804040][b]=[/b][/color] wshShell[COLOR=#804040][b].[/b][/color]exec[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"%comspec% /c ver"[/color][COLOR=#804040][b])[/b][/color]
os_version [COLOR=#804040][b]=[/b][/color] get_os_version[COLOR=#804040][b].[/b][/color]stdout[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]readall[/color]
os_version [COLOR=#804040][b]=[/b][/color] [COLOR=#804040][b]mid[/b][/color][COLOR=#804040][b]([/b][/color]os_version[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]3[/color][COLOR=#804040][b],[/b][/color] [COLOR=#804040][b]len[/b][/color][COLOR=#804040][b]([/b][/color]os_version[COLOR=#804040][b])-[/b][/color][COLOR=#ff00ff]3[/color][COLOR=#804040][b])[/b][/color]

wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"Computer Name   : "[/color] [COLOR=#804040][b]&[/b][/color] computername
wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"Operating System: "[/color] [COLOR=#804040][b]&[/b][/color] os
wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"OS Version      : "[/color] [COLOR=#804040][b]&[/b][/color] os_version
wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"User Name       : "[/color] [COLOR=#804040][b]&[/b][/color] username

Example Output:
Code:
C:\Work>cscript /NoLogo sysvars.vbs
Computer Name   : MIKROM-PC
Operating System: Windows_NT
OS Version      : Microsoft Windows [Version 6.0.6002]
User Name       : Mikrom

The other part will be to write the results into CSV file - it could be the exercise for your homework :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top