Skip to main content

Posts

Showing posts with the label vbscript

WMIC restart wireless network via command line in Windows

How to restart WiFi or Wireless using command line in Windows? If the wireless devices, laptops or computers are connected to a domain such as active directory, or a centralized control. The command below can be created using a batch file and deploy to all controlled devices or computers. The command below, has been tested on a Windows 11 laptop and works fine. If nothing goes wrong, the command executes very fast. Here's the command, must be executed on an elevated command prompt or administrator prompt. wmic service where caption="WLAN AutoConfig" call stopservice && timeout 3 && wmic service where caption="WLAN AutoConfig" call startservice Timeout command is used in between stop and start, as this would give the first command to stop the service and after 3 seconds, another command is executed to start the service. Without the timeout command, the second command might not run  properly, since the first is still executed on the background. Jus...

Close all open notepad instances or processes in one go

If you’re an admin and manually checking logs for details and opening each file one by one. Then opening multiple instances of notepad is quite an everyday task. Or you just love notepad in making notes, documentations or other endless reasons to use notepad. Then it will be a headache in closing all the notepad instances that were opened. However, PowerShell can be used to close all instances of notepad all at once. No sweat in clicking each file one by one. PowerShell can handle it in one click of a button if you open the file via PowerShell ISE. Here’s a simple PowerShell code snippet to close all files in one shot. #========== $x = ( Get-Process | Where-Object   { $_ . ProcessName -EQ 'Notepad' }) . count   1 .. $x | % {    stop-process -name notepad –force } #=========== Yes, 2 lines of code can save you a lot of time. The above code can be used also to close other processes that has multiple instances open on the system. If uns...

PowerShell display pop-up message theVBScript way

Create a new object in PowerShell by referring to Wscript.Shell component. Here's the code to display a pop-up message using  PowerShell via VBScript components. #create Wscript.Shell object to $WshShell variable $WshShell = New-Object -ComObject WScript.Shell #This will display the members of WshShell #$WshShell | Get-Member #This will display the message for 5 seconds, even if the user does not click ok" $WshShell.Popup("Hello, remember to shutdown your PC! Long holiday is around the corner.", 5 , "A Gentle Reminder") #Sample image of the output above: Code below will display a warning sign and the message will stay until the OK button is clicked. #create Wscript.Shell object to $WshShell variable $WshShell = New-Object -ComObject WScript.Shell #This will display the message until the OK button is clicked and also display the warning sign $WshShell.Popup("Hello, remember to shutdown your PC! Long holiday is around the corner.", 0 , "A Gentl...

Use PowerShell in Excel VBA

VBA in Excel is very helpful since it can run things without any human intervention, or technically it can run task and automate things and just get the result. VBA coupled with PowerShell can even be more interesting. Of course, there is always some drawback or pros and cons. Bad actor can take advantage of VBA and PowerShell to run malicious software on user’s computer. For most users who are not aware or doesn’t believe that VBA and PowerShell can be used to steal data, one common reaction is; Is it possible? Or you are just trying to exaggerate and scare people? As the odds say, to see is to believe. Or to see it in action is one thing and trying to educate users is another thing. Cyber Security is a task that everyone should be a part of, a chain is useless if one its link is weak. Which is basically, true in digital world. The company may spend thousands of moneys on Firewall, Anti-Virus and other devices or software to thwart attack but just a simple click on a Phishin...

PowerShell Get running processes and its command line path

How to get running processes with PowerShell using WMI and display its path. PowerShell below will display the path and also the command line of the process on how the process was executed. The code below will also display the process-id, the process-id or PID can also be supplied to an application called handle64 from SysInternal tools. This tool is quite cool since it will display more info about the PID supplied to handle application. Download link for handle64: https://docs.microsoft.com/en-us/sysinternals/downloads/handle Example output of handle64: Skype.exe pid: 42360 DESKTOP-Name\iuser-xname    40: File          C:\Windows    84: File          C:\Program Files (x86)\Microsoft\Skype for Desktop   24C: File          C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b23cb64144ccf1df_6.0.19041.1_none_fd031af4F787f5b0106f2   380: File          C:...

Compare multiple variables Conditions with if else in PowerShell

Multiple conditions to evaluate is sometimes necessary in order to decide whether the script should continue to execute a specific command or do another process. PowerShell is able to do this kind of task using if else statement. Example script below just shows 3 variables that should match and it will output "OK", the output is just a write-host command but it could be replaced with other codes. And if one of the statements does not match the "else" statement is executed. Example code: All statements or condition matches $var1 = "Online" $var2 = "Running" $var3 = "Proceed"   if (( $var1 -eq "Online" ) -and ( $var2 -eq "Running" )   -and ( $var3 -eq "Proceed" )) {   write-host "OK"   } else {   write-host "Not OK unable to Proceed"   } Output: OK One of the variable does not match: $var1 = "Online" $var2 = "Running" $var...