Saturday, 24 January 2015

Map network share to a drive letter, permanently and reliably.


I often want to access a shared network folder as at drive letter. Using "subst", "net use", "visual subst" have given variable results. Often a drive letter would be randomly missing after a reboot, not show up in admin mode or kick in too late resulting in "drive X doesn't exist" style messages.

A google on the subject highlighted the DosDevice registry method.

http://en.wikipedia.org/wiki/SUBST#Method_3

It didn't seem clear on its use in network shares. So after a lot of experimentation I found something that worked.

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"X:"="\\??\\UNC\\NetworkServer\\SharedFolder"

Copy the above to a .reg file, replace "NetworkServer", "SharedFolder" with your needs and run the reg.

Reboot and you are sorted. It will set up the drive letter on each reboot before anything gets launched. Both admin and user will see the drive letter. Bliss!

To verify, bring up a cmd prompt, enter "subst" and you should see something like:
X:\: => UNC\NetworkServer\SharedFolder

Wednesday, 26 June 2013

Windows context menu fragments left on desktop

Selected Item in Context Menu stays visible forever. I right click, up pops the context menu, I select a menu item, the context menu disappears, but leaves the selected menu item permanently visible on top of all other desktop windows. Annoying!! I've had this occur a lot in XP and now Win7 too. Finally I find a solution.. Kill the Desktop Window Manager (dwm.exe) in the task manager. It will restart itself and the zombified menu item will disappear.

UPDATE: 

    Alternatively, and much safer.. Set the desktop bit depth to a different bit depth (16bit), then select NO when asked to keep the setting. The screen gets refreshed, orphan elements disappear. Simple and effective.

UPDATE:

..but not permanent.

Maybe more luck with this..


Nope, fragments just reappear soon enough. Grr..


Friday, 14 June 2013

Symlinks in perforce in windows

Basically, if you are getting small files where symlinks should be, run perforce as administrator. Fuller description here : http://answers.perforce.com/articles/KB_Article/Enabling-Symlinks-on-Windows

Thursday, 30 May 2013

Visual Studio 2012 - "Project file '' has been renamed or is no longer in the solution"

Sometimes when messing about with projects, this unhelpful popup will plague you.

To get some more info about the actual cause..

1. Build this - https://github.com/CoherentLabs/DumpReferencesAddIn

2. Create C:\Users\\Documents\Visual Studio 2012\Addins 

3. Copy in there DumpReferencesAddIn.dll which you built and DumpReferencesAddIn.AddIn which you didn't. 

4. Restart VS2012, load your troublesome solution. 

5. Right click on the solution and select "Dump References". 

6. Enjoy.

Saturday, 18 May 2013

Use a custom icon in a dialog box in windows

When creating a windows dialog, the icon in the top left corner is the dull standard one. Add your own funky alternative by adding this code! SendMessage(mainDialog,WM_SETICON,ICON_BIG,(LPARAM)::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_YOURICON))); SendMessage(mainDialog,WM_SETICON,ICON_SMALL,(LPARAM)::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_YOURICON))); SendMessage(mainDialog,WM_SETICON,ICON_SMALL2,(LPARAM)::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_YOURICON)));

Tuesday, 2 April 2013

Running commands after exe exit


I needed a EXE to call it's related uninstall.exe when it had finished running. There are many solutions to this but I was after something short and sweet.

Here's what I came across.
http://stackoverflow.com/a/3458433/2237946

so modified to my requirements..


std::string g_PostScript;
int main()
{

g_PostScript+="notepad.exe \"hello.txt\" & "; //add a command
g_PostScript+="uninstall.exe & "; //and another one..

//time to exit
ApplyPostScript();
return 0;
}
void ApplyPostScript()
{
if (g_PostScript.length()==0)
return;
g_PostScript="cmd.exe /C ping 1.1.1.1 -n 1 -w 3000 > Nul & "+g_PostScript;
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};

CreateProcess(NULL, (LPSTR)g_PostScript.c_str(), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}