Skip to content

Instantly share code, notes, and snippets.

@tuksik
Last active February 1, 2016 10:18
Show Gist options
  • Save tuksik/39a50f0937daff7d96d3 to your computer and use it in GitHub Desktop.
Save tuksik/39a50f0937daff7d96d3 to your computer and use it in GitHub Desktop.
win_cmd.md - Misc commands for windows

Add user as administrator

(http://www.windows-commandline.com/)

net user username password /ADD /FULLNAME:"User_Fullname"
net localgroup administrators username /add
wmic path Win32_UserAccount where Name='username' set PasswordExpires=false

or for the system

net accounts /MAXPWAGE:UNLIMITED

Networking

  • Finding computer name using IP
REM Simple scan in batch
FOR /L %%G IN (200,1,236) DO CALL :sub1 %%G
:sub1
echo ------------------ 192.168.0.%1 ---------------- >> loc_net.txt
NBTSTAT -A 192.168.0.%1 >> loc_net.txt

Firewall

  • Add a rule

netsh firewall set portopening protocol=TCP port=5800 name=vnc5800 mode=ENABLE profile=All

or

netsh advfirewall firewall add rule name="vnc5800" dir=in action=allow protocol=TCP localport=5800

netsh advfirewall firewall add rule name="FireBird3050" dir=in action=allow protocol=TCP localport=3050

  • Check it netstat -na -p tcp|findstr 3050

Login scripts

( http://www.robvanderwoude.com/loginscripts.php )

  • Connect network drives

NET USE H: \\CompanyServer\%UserName% /PERSISTENT:No IF ERRORLEVEL 1 ( ECHO Error mapping drive H: )

Console

http://stackoverflow.com/questions/1333589/how-do-i-transform-the-working-directory-into-a-8-3-short-file-name-using-batch

  • Short local path under c:\Program Files\

for %%f in ("%cd%") do SET LOCALPATH=%%~sf

SystemInfo

systeminfo > info.txt
  • Finding disconnected sessions with qwinsta or query

qwinsta /server:theserver_or_ip

  • Killing disconnected sessions with rwinsta or reset

rwinsta sessionid /server:theserver_or_ip


How to change the System Regional Settings in Windows(VBS)

When the script finishes running, Windows Console will display brief information about the script to let you know the execution result.

Note

Please replace the following data before you execute the script.

strCountry = "United States"
strshortDateValue = "M/d/yyyy"
strlongDateValue = "dddd, MMMM d, yyyy"
strshortTimeValue = "h:mm tt"
strlongTimeValue = "h:mm:ss tt"
strfirstDayOfWeekValue = "6"

And we can only set the number to the 'FirstDayOfWeek' parameter, for example in English format, details as follow:

6 – Sunday
0 – Monday
1 – Tuesday
2 – Wednesday
3 – Thursday
4 – Friday
5 - Saturday
Const HKEY_CURRENT_USER = &H80000001 
strComputer = "." 
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") 
regKeyPath = "Control Panel\International" 
 
strCountry = "United States"  
strshortDateValue = "M/d/yyyy" 
strlongDateValue = "dddd, MMMM d, yyyy" 
strshortTimeValue = "h:mm tt" 
strlongTimeValue = "h:mm:ss tt" 
strfirstDayOfWeekValue = "6" 
 
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sCountry", strCountry 
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sShortDate", strshortDateValue 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment