Wednesday, 29 August 2018

Command Line - Close Chrome From Bat File

taskkill /IM chrome.exe /F

Shut Down The Computer With a Batch File

shutdown.exe /s /t 00

Restart The Computer With a Batch File

shutdown.exe /r /t 00

Batch Script To Automatically Reload explorer.exe

taskkill /IM explorer.exe /F
start explorer.exe

Batch File To Open Credential Manager

@echo off
START /min rundll32.exe keymgr.dll,KRShowKeyMgr
exit

Copy Files From One Folder To Another?

xcopy /s D:\ C:\Users\TEST_104_2\Desktop\

Batch File To Delete Temporary Files Windows 10

@ECHO off 
DEL /F /S /Q %TEMP%

cd C:\Users\%username%\AppData\Local
 rmdir /S /Q Temp

del C:\Windows\Prefetch\*.* /Q

del C:\Windows\Temp\*.* /Q

del C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Recent Items*.* /Q

Connect To SVN Command Batch File

CMD /c nslookup SERVER.ABC.local
CMD /c pathping SERVER.ABC.local

pause

Batch File To Clear ALL Browsers Cookies & History

@echo off

rem IE
taskkill /F /IM iexplore.exe
start "" "C:\Windows\System32\rundll32.exe" InetCpl.cpl,ClearMyTracksByProcess  255

:: Parse the Local AppData sub path
call :Expand xAppData "%%LocalAppData:%UserProfile%=%%"

set "xFirefox=\mozilla\firefox\profiles"
set "xChrome=\google\chrome\user data"

:: Start at the User directory
pushd "%UserProfile%\.."

taskkill /F /IM firefox.exe
taskkill /F /IM chrome.exe

:: Loop through the Users
    for /D %%D in (*) do if exist "%%~fD%xAppData%" (
    rem Check for Firefox
    if exist "%%~fD%xAppData%%xFirefox%" (
        rd /s /q "%%~fD%xAppData%%xFirefox%"
    )

   rem Check for Chrome
   if exist "%%~fD%xAppData%%xChrome%" (
        rd /s /q "%%~fD%xAppData%%xChrome%"
    )
)
popd
goto End


::::::::::::::::::::::::::::::
:Expand <Variable> <Value>
if not "%~1"=="" set "%~1=%~2"
goto :eof


:End
endlocal

Adding Login Information To The Credential Manager

echo off
cmdkey /add:server /user:sarin /pass:123
pause

Convert Rows Into Comma Separated Values In A Column SQL Server

DECLARE @COLS    AS NVARCHAR(MAX)

SELECT @COLS = STUFF((SELECT ',' + QUOTENAME(substring(Convert(varchar,D,103),0,3))
from TempAttendRegister
where D >= @startdate
and D <= @enddate
group by D
order by D
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)') 
,1,1,'')

Check If Boolean Value Exist in a Data Table C#

bool BlnSelect = DTTable.AsEnumerable().Any(row => Convert.ToBoolean(1) == row.Field<bool>("SELECT"));
if (BlnSelect)
{
    return true;
}
else
{
    return false;
}

Boolean Value Column Data Filter A Data Table Dynamically Using LINQ With C#?

bool BlnSelect = DTResult.AsEnumerable().Any(row => Convert.ToBoolean(1) == row.Field<bool>("SELECT"));
if (BlnSelect)
{
DataTable _DTUpdate;
_DTUpdate = DTResult.AsEnumerable().Where(row => row.Field<bool>("SELECT") == true).CopyToDataTable();
return true;
}
else
{
return false;
}

LINQ Query on Data Table To Check If Record Exists

bool BlnSelect = DTTable.AsEnumerable().Any(row => Convert.ToBoolean(1) == row.Field<bool>("SELECT"));
if (BlnSelect)
{
    return true;
}
else
{
    return false;
}

Split Comma-Separated Values C#

string pStrCommaSeparatedList = "A,B,C,D,E,F,G,H";
string pStrResult = string.Empty;
string[] pStrCommaValues = pStrCommaSeparatedList.Split(',');
for (int i = 0; i < pStrCommaValues.Length; i++)
{
        pStrResult = pStrCommaValues[i].ToString();
}

Comma Separated String Filter Data Table C#

string pStrEmpEditValue = CmbValue.EditValue.ToString();

DataTable table = new DataTable();
table.Columns.Add("value", typeof(string));
string[] values = CmbValue.EditValue.ToString().Split(',');

for (int i = 0; i < values.Length; i++)
{
table.Rows.Add(new object[] { values[i].ToString().Trim() });
}

DataTable _Final = DTResultSave.Clone();
_Final.Rows.Clear();
foreach (DataRow item in table.Rows)
{
String author = item["value"].ToString().Trim();
//bool contains = DTResult.AsEnumerable().Any(row => author.ToString().ToUpper() == row.Field<String>("EmpCode"));
DataRow[] rowsToCopy;
rowsToCopy = DTResultSave.Select("EmpCode='" + author.ToString().ToUpper() + "'");
if (rowsToCopy.Any())
{
foreach (DataRow temp in rowsToCopy)
{
_Final.ImportRow(temp);
}
}
}

Data Set Empty Or Not Check C#

bool IsEmpty(DataSet _DataSet)
{
return !_DataSet.Tables.Cast().Any(x => x.DefaultView.Count > 0);
}