Skip to content

Instantly share code, notes, and snippets.

/***MS EDGE*/
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/K " + "\"" + @"%windir%\explorer.exe shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge
" + "\" & exit");
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = true;
processInfo.RedirectStandardOutput = false;
@lockworld
lockworld / File is in use by another user - ME.md
Last active February 6, 2018 14:40
When you have problems on the network, here are some helpful solutions...

Ever get that annoying error when opening an office file is locked for editing by another user...and that user is YOU?

Try these steps to resolve:

Source: MrExcel.com

I'm in XP and my file is on a shared drive. This solution worked for me: Right-Click on My Computer and select Manage. Then right-click on Computer Management in the Left Panel and click "Connect to another Computer ..." and then select the server your locked file is on. (Skip that if it's on your local drive.) Then expand System Tools and Shared Folders, and click on Open Files. I found my locked file in that list. You can right-click on the file name and select "Close Open File" if you have system permissions to do that. If you don't, you have to ask an admin to do it for you. It worked for me after our admin showed me how.

Bob L

/*
If you want to add a column with random numbers as part of an INSERT statement, you can't use the RAND() function becuase you will always get the same number.
Instead, use the following code, which will return a random number between 0 and one less than the number following the modulus operator
*/
SELECT ABS(CHECKSUM(NewId())) % 6 -- this will return a random number between 0 and 5
SELECT (ABS(CHECKSUM(NewId())) % 5) + 1 -- this will return a random number between 1 and 5
var myShipVia = (from ShipVia_row in ttShipHead
where ShipVia_row.ShipViaCode=="12345"
select ShipVia_row).FirstOrDefault();
if (myShipVia!=null)
{
ShipViaDisabled = myShipVia.UDField<bool>("Disabled_c");
}
/*
# In this gist, we create a PowerShell script that, when run, will prompt the user for the following variables:
# * $SSRSServer [The server name or domain name of the report server]
# * $SSRSPath [The SSRS folder path for the folder containing the .rdl files you wish to download]
# * $Destinationpath [The local folder you wish to store the downloaded .rdl files in]
#
# When run, the user will supply the variables and the script will go out to the report server and individually download every .rdl file from that folder on the report server to the user's local machine in the location specified.
# Set Variables from User Input
$SSRSServer = Read-Host("Enter the report server name or domain name (Without http:// or any subdirectories)")
@lockworld
lockworld / !Run a .bat file with administrative permission without user interaction.md
Last active April 28, 2020 12:29
Run a script with an administrator's account without any user interaction

In this gist, we see how to run any .bat file (or any executable at all) either elevated ("Run as administrator") or with specific user credentials, all without any interaction from the user.

This is particularly useful in creating a GPO to pass out to network users to run a patch or script that requires specific permissions.

Steps

Create a batch file that will be pushed out to users via GPO, following the example in "RunAsOther script.bat" (below)

  • Replace {TaskName} with a unique name for your task. I suggest including a datestamp
  • Replace {\path\to\my.bat} with the path to your .bat file or executable that needs to be run on the user's machines.
  • Replace {domain\username} with the domain and username of the account you want to use to run this task. [OPTIONAL]
@lockworld
lockworld / FindNameInDefinitions.sql
Last active January 9, 2021 03:51
Thse queies can be used to find information in tables, views, or object definitin
/*
Use this query to find the name of a database that has been renamed so you can change the name in all views, stored prcedures, functions, etc.
*/
DECLARE @Search varchar(255)
SET @Search='%Old_DB_Name%'
SELECT DISTINCT
DB_NAME() as DBNAME, schema_name(o.schema_id) as SchName, o.name AS Object_Name,o.type_desc
FROM sys.sql_modules m
INNER JOIN sys.objects o ON m.object_id=o.object_id
@lockworld
lockworld / Find size of specific tables.sql
Last active November 24, 2021 19:31
SQL Server Database and Server commands (These are for when you need to go beyond just table-level access).
SELECT
t.NAME AS TableName,
p.rows AS RowCounts,
CONVERT(DECIMAL,SUM(a.total_pages)) * 8 / 1024 / 1024 AS TotalSpaceGB,
SUM(a.used_pages) * 8 / 1024 / 1024 AS UsedSpaceGB ,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024 / 1024 AS UnusedSpaceGB
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
@lockworld
lockworld / logfile.cs
Last active June 23, 2017 18:03
Text formatting in C#
//Ref: https://stackoverflow.com/a/2866650
var timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd hh':'mm':'ss.fff");
var msgType = "INFORMATION";
var msgText = "This is an example of how to format a text string to align fragments on a line, like a typical log file.";
LogFile.Write(string.Format("{0,-25} {1,-15} {2}", timestamp, msgType, msgText));
@lockworld
lockworld / RecycleBin.cs
Last active June 19, 2017 19:00
Working with files in a C# application
using Shell32;
using System;
namespace RecycleBin
{
class Program
{
static void Main(string[] args)
{