Dim command
Dim status
command = "psexec \\ 172.16.11.63 netsh advfirewall firewall set opmode "
status = "enable"
Set oShell = CreateObject("WScript.shell")
oShell.CurrentDirectory = "C:\PSexec\"
oShell.Run "command.com /k " & command & status
Set oShell = Nothing
Hi, I have a sample script here that suppose to enable my firewall if it is disabled, but it doesn't work, however if I change my status to disable and my firewall was turned on, after executing the program, the enabled firewall will be disabled. Any ideas? Thanks.
You seem to be mixing commands for different versions of Windows. According to this article you should use
netsh firewall set opmode ENABLE
in older versions, but in 2008 and Vista (and I assume Win7 too) you should be using
netsh advfirewall set currentprofile state on
So either remove the advfirewall from your command if it's XP or 2003, or change it completely to the new command if it's a newer Windows version.
Related
I was creating a batch script to run several commands to enable winrm, changing network category and such and I got across a problem with the netsh command, specifically netsh advfirewall firewall set rule group=”Network Discovery” new enable=yes
After digging around and messing with UAC and registry I understood my problem: Windows language.
So the command is setting the rule to the Network Discovery, however in my language (portuguese btw) the group is called Deteção de Rede and thus making the script unable to run across several Windows machines with different languages, making the user enable network sharing manually.
My question is: Is there global way of calling the Network Discovery group? or creating a new group linking to it?
This is my script btw:
#ECHO ON
REM Run as admin
powershell.exe /c Get-NetConnectionProfile;
powershell.exe /c Set-NetConnectionProfile -NetworkCategory Private;
powershell.exe /c netsh advfirewall firewall set rule group=”Deteção de Rede” new enable=yes
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm set winrm/config/service #{AllowUnencrypted="true"}
cmd.exe /c winrm set winrm/config/service/auth #{Basic="true"}
#ECHO Done.
Thankfully to #lit I found a way to set the rules to the group.
Used the command powershell.exe /c netsh advfirewall firewall set rule group="#FirewallAPI.dll,-32752" new enable=Yes to enable Network Sharing and powershell.exe /c netsh advfirewall firewall set rule group="#FirewallAPI.dll,-28502" new enable=Yesto enable files and print sharing
(if you want to use this to target a windows machine you may want to activate them both) and now i'm able to run my ansible playbook to windows
How to access Command Prompt in remote machine using VBScript?
We are in process of creating a tool to fetch component services and its status on remote machines.
Currently we are able to achieve this in our local machine by using the below code:
Dim objShell : Set objShell = CreateObject("WScript.Shell")
Set getvalue=objShell.Exec("cmd.exe /C sc queryex type= service state= all")
Do
output = getvalue.StdOut.ReadLine
MsgBox output
Loop While getvalue.StdOut.AtEndOfStream = False
But we need to achieve the same in remote machine.
Set objWMIService = GetObject("winmgmts:\\127.0.0.1\root\cimv2")
Set config = objWMIService.ExecQuery("Select * From Win32_Service")
For Each thing in Config
Msgbox thing.Caption
Next
Is how we query services in vbscript. These are the properties available. https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx
I have a script that sets up SQL Server after it has installed. It detects if the windows firewall is on and adds ports to the windows firewall service.
However it seems very confusing as to how to actually establish if it's "really" running or not.
I thought by checking if the service was running 'then doing stuff or not' would suffice, but seems even if the windows firewall is OFF the service still runs, so the port adding netsh script section runs unnecessarily.
I have also looked at settings in the registry and they also can be set to on, even if the service is running but the firewall is off.
Any pointers to perhaps a better method to avoid running parts of the script without really needing to.
Usually installing server 2008 mostly, some 2012 & the odd 2016. Thanks.
sc query MpsSvc | find "RUNNING" >nul
IF %ERRORLEVEL% EQU 0 (goto firewall) ELSE (goto start)
The proper method to disable the Windows Defender Firewall is to disable the Windows Defender Firewall Profiles and leave the service running.
So…
Turn Off using batch file:
#NetSh AdvFirewall Set AllProfiles State Off
Turn On using batch file:
#NetSh AdvFirewall Set AllProfiles State On
Turn Off using Powershell from a batch file:
#Powershell -C "Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False"
Turn On using Powershell from a batch file:
#Powershell -C "Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True"
To determine the state, you could parse the result of Show:
#NetSh AdvFirewall Show AllProfiles State|Find /I " ON">Nul&&(#Echo Is On)||#Echo Is Off
I want to enable and disable manual proxy setup in windows 7,8 and 8. I want to toggle the manual proxy setup option using command script. I want to create a .bat file using command line and whenever I click on that .bat file, the manual proxy setup option will be toggled. I don't know the command for doing my job. I want to know the command for this job.
I agree with #Quirk this question is better placed in the super user group, but at the same time, users are drawn more often to StackOverflow and get discouraged when they don't find the answer.
Here is something I came up with, also my taught process:
all of Windows configurations that are flags or simple values are kept in the registry
you can manipulate the registry with the REG command
REG /? shows you what you can do
with regedit you can search the registry (F3) for your proxy host name
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings
once you found the REG_KEY you are ready to write your script
in conclusion:
here is your 'command' for enabling your proxy:
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
here is your 'command' for disabling your proxy:
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
It works, the value is set, but I am pretty sure your Network Settings Window does not get the update until the next time you open it.
Hope this helps.
I want to enable and disable manual proxy setup
To enable:
netsh winhttp set proxy myproxy:80
To disable:
netsh winhttp reset proxy
To show the current settings:
netsh winhttp show proxy
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
netsh - Configure Network Interfaces, Windows Firewall, Routing & remote access.
Netsh commands for Interface IP
Netsh Commands for Wireless Local Area Network (WLAN)
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "calc" ,,true
msgbox "Calc finished"
WSHShell.Run "userinit.exe"
I need Taskmanager disabled from the beginning of the script until userinit.exe gets executed. I'm using Win 7 and i don't know how to do it. (I searched a lot but nothing worked)
You can set a registry value, using the registry editor cmdline equivalent: reg.exe. Here's an example:
WSHShell.Run("Reg.exe add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /t REG_DWORD /d 1 /f", 0, 1)
In order to enable it, reset the same registry value: /d 0.
Details can be found in [TweakAndTrick]: Enable Task Manager disabled by Administrator or Virus in Windows.
Note that depending on your user, some registry key permissions adjustments might be necessary.