Setup schedule job to run the following command every day at 1:30 am.
forfiles.exe /p C:\WINDOWS\system32\LogFiles\W3SVCXXXXXXXXXX /s /m *.log* /d -30 /c "cmd /c del /q @path"
It will delete logs older than 30 days
Setup schedule job to run the following command every day at 1:30 am.
forfiles.exe /p C:\WINDOWS\system32\LogFiles\W3SVCXXXXXXXXXX /s /m *.log* /d -30 /c "cmd /c del /q @path"
It will delete logs older than 30 days
Log pruning on Sharpoint Service 3.0 server
Create file name by date and time
echo foo > "%DATE:/=-%.txt"
echo foo > "%DATE:/=-%%TIME::=-%.txt"
Rename file name by date
ren installedprogs.txt installedprogs_"%DATE:/=-%.txt"
create and rename name file by date
停用 Windows 2000 / XP 的 USB / Storage / Cdrom / Floppy 與 command line 寫法
http://evil-ms.blogspot.com/2010/11/windows-2000-xp-usb-storage-cdrom.html
停用 Windows 2000 / XP 的 USB / Storage / Cdrom / Floppy 與 command line 寫法
I use a tool call "CPAU" and "Bat to exe converter" to create an execute file for the user to use it normal user right to run an program need administrator privilege.
Step 1:
Use CPAU to encrypt the command to "runas" the program by using the service account (local account with admin right - not local admin (For security reason)
CPAU.exe -u <username> -p <password> -ex "C:\Program Files\abc00.exe" -enc -file "C:\Program Files\runapp.txt"
Step 2:
Create a runapp.bat to decrypt the encrypted file "runapp.txt"
cpau.exe -dec -file "C:\Program Files\runapp.txt"
Step 3:
Use Bat to exe converter to convert the runapp.bat to runapp.exe
Step 4:
Copy the CPAU.exe to "System32" that machine. And Copy the "runapp.txt" and "runapp.exe" to the C:\Program Files\
Step 5:
Create the local service account
Step 6:
Create a shortcut to runapp.exe on the desktop
Remark:
1. Since the CPAU encryption is not very strong, I suggest that we create the other local account with admin privilege at a service account and also prevent the local admin account password change.
2. The service account password should be 14 digit or above to prevent hash attack
Reference:
CPAU
http://www.joeware.net/freetools/tools/cpau/index.htm
Bat to exe converter
http://www.f2ko.de/English/b2e/index.php
CPAU and Bat to exe converter
Delete files and folder more than 30 day
forfiles /p "c:\temp\abc" /s /c "cmd /c rmdir /s/q @path" /d -30
forfiles /p "c:\temp\ghj" /s /c "cmd /c if @isdir==FALSE echo del @file & del @file" /d -30
forfiles /p "c:\temp\xyz" /s /c "cmd /c rmdir /s/q @path" /d -30 /m xyz_*
Delete files and folder more than 30 day
Create folder with permission
@echo off
for /f %%i in (x:\abc\namefile.txt) do mkdir g:\backup\%%i
g:
cd g:\backup\
FOR /D %%A IN (*) DO cscript x:\abc\xCACLS.vbs g:\backup\%%A /T /E /G domain\%%A:F
Remark: For/D %%A IN (*) which is the command running path (e.g. It running in g:\backup\), it will scan all folder in g:\backup\
The backup folder users permission need to set this folder only, otherwise it will inherited to the \backup\%username%
map drive by username
net use Z: \\abc_server\backup\%username%
Create folder with permission and map drive by username
To Create folder and grant permission to user to access this folder and his/her own folder:
Prepare the username into a file call namefile.txt in X:\backup\namefile.txt
Batch to create folder name from a name list (Must be same at Windows login name):
@echo off
for /f %%i in (X:\backup\namefile.txt) do mkdir %%i
(Remark: if running in console/command prompt it should be “for /F %i in (X:\backup\namefile.txt) do mkdir %i”)
To grant permission to the individual folder:
@echo off
FOR /D %%A IN (*) DO cscript xCACLS.vbs X:\backup\%%A /T /E /G MyDomain\%%A:F
To Create folder and grant permission to user to access this folder and his/her own folder by batch
The user logon script:
Check temp exist and deploy sleep.exe
***************************************************************
C:
if not exist c:\temp\ (md C:\temp)
cd C:\temp
if exist C:\temp\sleep.exe (echo exist!)
if not exist C:\temp\sleep.exe (copy \\SRV\remoteinstall$\Sleep\sleep.exe C:\Temp\ /Y)
***************************************************************
The Startup Script have been create for client at the following:
***************************************************************
C:\Temp\sleep.exe 55
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO FOR /F %%B IN ('DIR/B "C:\Documents and Settings\%%A\My Documents\My Received Files"') DO copy NUL "C:\Documents and Settings\%%A\My Documents\My Received Files\%%B\history\dont_delete.txt"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO FOR /F %%B IN ('DIR/B "C:\Documents and Settings\%%A\Application Data\Skype"') DO copy NUL "C:\Documents and Settings\%%A\Application Data\Skype\%%B\dont_delete.txt"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO "C:\Program Files\Eraser\"eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --dir="C:\\Documents and Settings\\%%A\\Application Data\\Skype\\,includeMask=*.dbb,excludeMask=*.FOLDER"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO "C:\Program Files\Eraser\"eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --dir="C:\\Documents and Settings\\%%A\\My Documents\\My Received Files\\,includeMask=*.xml,excludeMask=*.FOLDER"
***************************************************************
***************************************************************
@echo off
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO "C:\Program Files\Eraser\"eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --dir="C:\\Documents and Settings\\%%A\\Application Data\\Skype\\,includeMask=*.dbb,excludeMask=*.FOLDER"
FOR /F %%A IN ('DIR/B "C:\Documents and Settings"') DO "C:\Program Files\Eraser\"eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --dir="C:\\Documents and Settings\\%%A\\My Documents\\My Received Files\\,includeMask=*.xml,excludeMask=*.FOLDER"
***************************************************************
usage: Eraser <action> <arguments>
where action is
help Show this help message.
addtask Adds tasks to the current task list.
querymethods Lists all registered Erasure methods.
global parameters:
--quiet, -q Do not create a Console window to display progress.
parameters for help:
eraser help
Eraser querymethods
Method GUID
-------------------------------------------------------------------------------
U Gutmann 1407fc4e-feff-4375-b4fb-d7efbb7e9922
U Gutmann Lite ae5eb764-41b0-4601-bdf2-326b5838d44a
U US DoD 5220.22-M (8-306./E, C & E) d1583631-702e-4dbf-a0e9-c35dba481702
U RCMP TSSIT OPS-II f335cc40-5de5-4733-90b1-6957b4a45688
U Schneier 7 pass b1bfab4a-31d3-43a5-914c-e9892c78afd8
U German VSITR 607632b2-651b-4935-883a-bdaa74febb54
U US DoD 5220.22-M (8-306./E) ecbf4998-0b4f-445c-9a06-23627659e419
U British HMG IS5 (Enhanced) 45671da4-9401-46e4-9c0d-89b94e89c8b5
U US Air Force 5020 7bf5b185-8ea5-4e12-83f1-f6c2efb3d2c2
U US Army AR380-19 0fe620ea-8055-4861-b5bb-bd8bdc3fd4ac
U Russian GOST P50739-95 92681583-f484-415f-a66c-cc210222edc5
U British HMG IS5 (Baseline) 9acdbd78-0406-4116-87e5-263e5e3b2e0d
U Pseudorandom Data bf8ba267-231a-4085-9bf9-204de65a6641
First/last 16KB Erasure 0c2e07bf-0207-49a3-ade8-46f9e1499c01
Press enter to continue . . .
Some example for Eraser command:
Erase a specific file:
C:\Program Files\Eraser>eraser addtask -q --schedule=now --file=C:\\Temp\\test\\a.xml
C:\Program Files\Eraser>eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --file=C:\\Temp\\test\\a.xml
C:\Program Files\Eraser>eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --dir=C:\\Temp\\test\\,includeMask=*.xml
C:\Program Files\Eraser>eraser addtask -q --method=1407fc4e-feff-4375-b4fb-d7efbb7e9922 --schedule=now --dir=C:\\Temp\\test\\,includeMask=*.dbb
User eraser to delete MSN/Skype history + Check the temp folder exist and copy file to this folder
The bat job #1
1.Copy file from d:\backup to g:\backup folder or Move file from d:\backup to g:\backup folder
robocopy e:\Backup f:\Backup /e (For Copy file)
robocopy e:\Backup\ f:\Backup\ /MOV (For Move file - delete from source after copying)
The bat job #2
2. Delete files more than 15 day
forfiles /p "f:\backup" /s /c "cmd /c if @isdir==FALSE echo del @file & del @file" /d -15
robocopy -copy and move and forfiles - Delete files more than 15 day
Use psexec remote run bat to a target machine by using share driver
The bat file at the following:
**********************************************************
route -f
route add 0.0.0.0 mask 0.0.0.0 172.17.50.30 (Fake Gateway IP Address) metric 1 -p
Copy C:\WINDOWS\system32\drivers\etc\hosts C:\WINDOWS\system32\drivers\etc\hosts_bk /y
echo 127.0.0.1 (Fake IP of the File Server, AD …..) ServerX >> c:\Windows\system32\drivers\etc\hosts
echo 127.0.0.1 (Fake IP of the File Server, AD …..) ServerX.abc.com >> c:\Windows\system32\drivers\etc\hosts
********************************************************
psexec.exe \\target_hostname -u (localadmin) -p (localadmin's password) \\server\share$\
Disconnect the client’s network connection remotely
Add IP address
IF NOT EXIST C:\WINDOWS\system32\drivers\etc\hosts_o Copy C:\WINDOWS\system32\drivers\etc\hosts C:\WINDOWS\system32\drivers\etc\hosts_o
Copy C:\WINDOWS\system32\drivers\etc\hosts C:\WINDOWS\system32\drivers\etc\hosts_bk /y
echo 1.5.3.8 x.xxx.com >> C:\WINDOWS\system32\drivers\etc\hosts
Remove IP address
Copy C:\WINDOWS\system32\drivers\etc\hosts C:\WINDOWS\system32\drivers\etc\hosts_bk2 /y
Copy C:\WINDOWS\system32\drivers\etc\hosts_o C:\WINDOWS\system32\drivers\etc\hosts /y
Batch to add/remove IP address in hosts file
C:\Program Files>dir /a /b /-p /o:gen /s >filelisting.txt
C:\Program Files>dir /a /-p /o:gen /s >list.txt
Copy all Filenames in a Directory to a Text File
Remote Script
Utility lets you execute commands and scripts on the remote machine.
Utility lets you execute commands and scripts on the remote machine
Check map driver present PC:
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.DriveExists("X:") Then
Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.Run ("E:\Testing_file\test2\map_drive_check.bat")
End If
The bat to record the hostname
hostname >> E:\Testing_file\test2\a.txt
check the map drive present remotely
It is create your host file and deploy it with a startup script which doesn't require that the user has admin rights since it runs on machine account.
Put your host file on a share and create a batch file with this line:
type \\server\sharename\hosts >>%systemroot%\system32\drivers\etc\hosts
Then go in your group policies:
Computer configuration / Windows settings / Scripts / Startup
and use your script. At next startup everyone will have new hosts file.
(Reference: http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_23790188.html)
GPO + bat file to edit host files
Dim DomainName
Dim UserAccount
Set net = WScript.CreateObject("WScript.Network")local = net.ComputerName
DomainName = "DomainName"
UserAccount = "userAccount"
set group = GetObject("WinNT://"& local &"/Administrators")on error resume next
group.Add "WinNT://"& DomainName &"/"& UserAccount &""
CheckError
sub CheckError
if not err.number=0 then
set ole = CreateObject("ole.err")MsgBox ole.oleError(err.Number), vbCritical
err.clear
else
MsgBox "Done."
end if
end sub
http://www.enterpriseitplanet.com/resources/scripts_win/article.php/3083571
(Domain PC) How to solve the local admin account locked
For the logon script,
The bat command
cscript //nologo %0\..\add_admin.vbs
How to use logon script to call a vbs