Quantcast
Channel: VBS script via GPO
Viewing all articles
Browse latest Browse all 8

VBS script via GPO

$
0
0

Hi, I have this script below. It works without any error on every my machine. But when I try to start it via GPO, there is no result, no errors. It just doesn't work.

I set this script on Computers obkect in Active Directory.

On Error Resume Next
Const strFolderName = "\\myserver\\OS\"
Set FSO = CreateObject("Scripting.FileSystemObject")
 
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
 
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
 
' Get information about this machine
Set WshNetwork = WScript.CreateObject("WScript.Network") ' used for Networking object control
UserName = UCase(WshNetwork.UserName)
ComputerName = UCase(WshNetwork.ComputerName)
EnvDomainName = UCase( WshNetwork.UserDomain )
Set WshNetwork = Nothing

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

For Each os in oss
    OSversion = Trim(os.Caption)
Next


If NOT (FSO.FolderExists(strFolderName + OSversion)) Then
FSO.CreateFolder(strFolderName + OSversion)
End if

strFileName = strFolderName & OSversion & "\" & ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject") ' used for file operations
Set objTextFile = objFSO.OpenTextFile (strFileName, ForWriting, True)
objTextFile.WriteLine OSversion & vbCrLf & ComputerName & vbCrLf & UserName & vbCrLf
objTextFile.Close


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images