Showing posts with the label Batch File

Map drive not working

Mapping drive can be set in different ways,  via group policy, using scripting (PowerShell, Vbscript, Jscript) or it can be set via command line.
Setting script via command line can be done easily using ”net” command, like the example below. The example below shows the syntax on how to map a drive or folder.

net use ?
The syntax of this command is:
NET USE [devicename | *] [\\computername\sharename[\volume] [password | *]]         [/USER:[domainname\]username]         [/USER:[dotted domain name\]username]         [/USER:[username@dotted domain name]         [/SMARTCARD]         [/SAVECRED]         [[/DELETE] | [/PERSISTENT:{YES | NO}]]
NET USE {devicename | *} [password | *] /HOME
Net use \\AD_Server\Working_folder  Z:
The command will map “Working_folder” to drive Z on the client PC.
The above command will not need a password  if run as a batch file and deploy as a logon script via group policy.
To delete the mapped drive : net use Z: /delete

Shutdown or reboot computers with user abort option in Windows

Disconnect Remote Desktop from command line

How to kill remote desktop sessions from the command line?
How to close RDC sessions from the command line?
One solution is to use batch file scripting or use PowerShell.
For old timers batch file might be the preferred solution because you don't need to install anything, it  comes in handy with the native command prompt.
Of course, PowerShell is also one of the best solutions; provided the environment is PowerShell ready.
The method used below utilizes batch file or the command prompt, just like the good old DOS environment of yesterday.
Command below can be run directly from the command prompt.
To use batch file scripting open notepad and save the file with ".bat"  file extension. Once saved as a batch file, the script is ready for automation with the help of Task Scheduler.
Here's the command:
for /f "tokens=2,5" %a in ('netstat -ano ^| find "3389"') do echo %a & tskill %b /v
For folks who just started to embark in batch file world,…

Check Domain Name, DHCP and IP Address

Copy all matching files

Windows delete files in all directories

Deleting files are good and bad.
It is good to delete files because it will tidy up your computer, get rid of unwanted or outdated files and free up space on the drive.
It is bad to delete file or files if no backup is available and the data is of great importance.
So deleting files should be done carefully and cautiously to make sure that deleted data will not be needed anymore.
How to delete files automatically in all folders and subfolders?
The batch file will come handy to automate file deletion.
Below is an example that deletes files on the temp folder for any “dll” files.
This can be applied to any folder path but don't do this on the c:\windows folder or the system will be completely unusable.
Open a command prompt and copy and paste the commands below or save it to notepad and run the script as a batch file.
C:\Users\\AppData\Local\Temp>FOR /f "tokens=*" %a in ('dir *.dll/B /S') DO del %a
Above command will find all the “.dll” files on the temp folder …