This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.vbs
72 lines (55 loc) · 2.49 KB
/
main.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
' Create Shell and FileSystemObject instances
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Define the file name for Wi-Fi details
Dim wifiDetailsFileName
wifiDetailsFileName = "wifi_passwords.txt"
' Get the script's directory
strScriptDir = objFSO.GetParentFolderName(WScript.ScriptFullName)
' Build the full path to the Wi-Fi details file
strFilePath = objFSO.BuildPath(strScriptDir, wifiDetailsFileName)
' Create the Wi-Fi details file if it doesn't exist
If Not objFSO.FileExists(strFilePath) Then
Set newFile = objFSO.CreateTextFile(strFilePath)
newFile.Close
End If
' Run the "netsh" command to show all profiles and save output to a temporary file
objShell.Run "cmd /c netsh wlan show profiles > """ & strScriptDir & "\profiles.txt""", 0, True
' Open the temporary file and read all Wi-Fi profiles
Set objFile = objFSO.OpenTextFile(strScriptDir & "\profiles.txt", 1)
Dim profiles
profiles = objFile.ReadAll
objFile.Close
' Extract profile names using regular expressions
Dim re
Set re = New RegExp
re.Global = True
re.IgnoreCase = True
re.Pattern = "All User Profile\s*:\s*(.*)"
Dim matches, match
Set matches = re.Execute(profiles)
' Open the Wi-Fi details file for appending
Dim wifiName, profileDetails, file
Set file = objFSO.OpenTextFile(strFilePath, 8, True)
' Loop through each profile and retrieve details
For Each match in matches
wifiName = match.SubMatches(0)
' Run the "netsh" command to show profile details and save output to a temporary file
objShell.Run "cmd /c netsh wlan show profiles """ & wifiName & """ key=clear > """ & strScriptDir & "\profile_details.txt""", 0, True
' Open the temporary file and read profile details
Set objFile = objFSO.OpenTextFile(strScriptDir & "\profile_details.txt", 1)
profileDetails = objFile.ReadAll
objFile.Close
objFSO.DeleteFile strScriptDir & "\profile_details.txt" ' Clean up temporary file
' Append profile details to the Wi-Fi details file
file.WriteLine("Profile: " & wifiName)
file.WriteLine(profileDetails)
file.WriteLine("--------------------------------------------------")
Next
file.Close
' Clean up temporary profiles file
objFSO.DeleteFile strScriptDir & "\profiles.txt"
' Run the helper script to close the "Done" message box after 500 ms
objShell.Run "wscript.exe """ & strScriptDir & "\closeDone.vbs""", 0, False
' Display "Done" message
WScript.Echo "Done"