How do I shutdown, restart, or log off Windows via a bat file?

The most common ways to use the shutdown command are: shutdown -s — Shuts down. shutdown -r — Restarts. shutdown -l — Logs off. shutdown -h — Hibernates. Note: There is a common pitfall wherein users think -h means “help” (which it does for every other command-line program… except shutdown.exe, where it means “hibernate”). They … Read more

Run Command Prompt Commands

this is all you have to do run shell commands from C# string strCmdText; strCmdText= “/C copy /b Image1.jpg + Archive.rar Image2.jpg”; System.Diagnostics.Process.Start(“CMD.exe”,strCmdText); EDIT: This is to hide the cmd window. System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = “cmd.exe”; startInfo.Arguments = “/C copy /b Image1.jpg + Archive.rar … Read more

Use grep –exclude/–include syntax to not grep through certain files

Use the shell globbing syntax: grep pattern -r –include=\*.cpp –include=\*.h rootdir The syntax for –exclude is identical. Note that the star is escaped with a backslash to prevent it from being expanded by the shell (quoting it, such as –include=”*.cpp”, would work just as well). Otherwise, if you had any files in the current working … Read more

How do I get the application exit code from a Windows command line?

A pseudo environment variable named errorlevel stores the exit code: echo Exit Code is %errorlevel% Also, the if command has a special syntax: if errorlevel See if /? for details. Example @echo off my_nify_exe.exe if errorlevel 1 ( echo Failure Reason Given is %errorlevel% exit /b %errorlevel% ) Warning: If you set an environment variable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)