Friday, January 10, 2014

WshShell | Get UserName and Other System details

Below is the shell script to fetch username and other system details,


Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FullName

SN = objUser.SN
givenName = objUser.givenName
sAMAccountName = objUser.sAMAccountName
department = objUser.department
company = objUser.company

strTitle = "ComputerName" & objSysInfo.ComputerName
strDepartment = "DomainDNSName" & objSysInfo.DomainDNSName
strCompany = "DomainShortName" & objSysInfo.DomainShortName
strPhone = "ForestDNSName" & objSysInfo.ForestDNSName

strTitle1 = "IsNativeMode" & objSysInfo.IsNativeMode
strDepartment1 = "PDCRoleOwner" & objSysInfo.PDCRoleOwner
strCompany1 = "SchemaRoleOwner" & objSysInfo.SchemaRoleOwner
strPhone1 = "SiteName" & objSysInfo.SiteName

msgbox strName & strTitle & strDepartment & strCompany & strPhone  & strTitle1 & strDepartment1 & strCompany1 & strPhone1 & SN & givenName & sAMAccountName & department & company

Thursday, January 9, 2014

WshShell | Code to change System Date

You might want to change the windows system Date/Time during a script runtime, below is the code for the same.

Var_Date="01.09.2014"
Dim WS
Set WS= CreateObject("WScript.Shell")
WS.run "cmd"
window("object class:=ConsoleWindowClass").Type "date " & Var_Date
window("object class:=ConsoleWindowClass").Type chr(13)
window("object class:=ConsoleWindowClass").Type "exit"
window("object class:=ConsoleWindowClass").Type chr(13)
Set WS= nothing