Preserve mapped drive letter information during UAC elevation - windows-vista

We have an application that needs to know the path that it is executed from (which is always a network path).
We set up part of our configuration based on the path that the application is launched from, and we really want that configuration to use mapped network drive paths instead of the UNC path to the resource.
What we've found is that when we launch our application without UAC elevation, we are able to get the directory that the application launched from using
GetModuleFileName(NULL, buf, sizeof(buf));
But when we launch elevated (which we actually need to do), the buffer returned gives us a UNC based path instead of a drive letter based path.
Note that we always launch from Windows Explorer by navigating into the folder tree of the mapped drive letter.
Does anyone have any suggestions on how to get the drive letter based path of the EXE from a process that is running elevated?

Mapped Network Drives with UAC

Related

a percentage sign shortcut to user desktop? (eg. %USERPROFILE% or %SYSTEMROOT%)

So I have been writing a short batch script to execute on multiple Windows 10 computers with desktop file location located differently. I cannot just insert my current desktop directory into the script and expect it to work on other machines as the directory includes username ("C:\Users\user_A\Desktop" and "C:\Users\user_B\Desktop" or even custom directories like "D:\MyFiles\Desktop") that varies depending on the machine. So is there a built-in "function" (eg. %userprofile% to go to the user's folder or %systemroot% to go to the Windows folder under C drive) that tells the script to reach for the actual location of the current user's desktop?
The closest I can find is %userprofile%\desktop
Not sure if it works when the desktop is redirected to a different drive.
Also if the script needs to be run as a different user (say admin) it would just point to admin\desktop.

WinAPI: How can I list shares connected by a UNC Path

Using a UNC path such as \\1.2.3.4\drive\dir\myfile.txt I can access files on a remote machine.
I can make a connection using WNetAddConnection2 programatically
or I can just type \\1.2.3.4\ in the explorer address bar, and then Windows will prompt me for user credentials etc.
How can I list the UNC drives that the local machine is connected to for the current user?
I tried this example using WNetEnumResource - it lists nothing I find useful.
I also found this example using NetShareEnum, but it seems only to list who is connected to a specified remote machine.
I want to list all UNC drives that the local machine is connected to (which must not have necessarily have a local drive letter).
How can that be done?

Reconnecting to a Mapped Drive after Server Restart from within PowerShell Script

I have a PowerShell v1 script that connects to a remote server via a mapped drive and moves files back and forth the remote server is identified by drive number "M" and also by UNC path REMOTESERVER\DATA:
(M:) \\REMOTESERVER\DATA
When the remote server reboots, I think that I am screwed because now the mapped drive will be inaccessible by the script.
The issue is not when the mapped drive actually disappears, it is that after reboot, authentication is needed and Windows apparently will not remember that.
How is this situation handled programmatically from within a PowerShell script?
Is there a way to reconnect to the mapped drive by writing some PowerShell code?
Just curious how this is accomplished?

cmd.exe and runcbl.exe errors

I have a program on my company network that I'm suddenly unable to open. When I try I get the following errors:
\Bpiserver\accounting\CSSI\lori1
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
Could not find C:\Windows\STATUS.*
another error box pops up on top of that one saying
Windows cannot find 'RUNCBL'.
I have searched the internet in every way I can and have not found one piece of info that relates to this specific problem.
I'm using Windows 7
I have run several antivirus programs and found no problems.
PLEEEEASE help! I am in HR and cannot run paychecks, etc until I can get into this program.
"RunCBL" may be a COBOL runtime/helper, which would make sense for a payroll app. It would be like trying to double-click a .doc or .docx file if Windows couldn't find the MS Word executable.
Either the file has been deleted, or your path has changed. (Right-click My Computer, go to Properties, Advanced, Environment variables.)
The UNC path is a common complaint. DOS/Windows scripts (.bat or .cmd files) don't like to start in network folders -- unless the network folder is mapped to a DOS-style drive letter. (In other words, you would have a virtual X: or Z: drive on your PC that pointed to \Bpiserver\accounting or \Bpiserver\accounting\CSSI.)
If you had a drive mapping and that got deleted somehow, that could account for all of these problems.
If you want further assistance you should probably post the contents of \Bpiserver\accounting\CSSI\lori1.cmd
My guess is that you do not have access to the network path needed to run that program.
UNC path: \\Bpiserver\accounting\CSSI\lori1
Also, it may be possible to disable this UNC check:
http://support.microsoft.com/kb/156276

I installed XAMPP in a virtual drive and now I can't run its services. Why?

The description is quite long. Please spend some time to read it. ^:)^
I have an old PHP application and I'm trying to test and debug it. Unfortunately, the application uses important data so I can't just click this and that. Now, what I'm trying to do is create a copy of the application in a different computer. From now on, I will call the computer running my original PHP application as 'Computer A' and the computer which I'm going to use to run the copy of the application as 'Computer B'.
To prevent missing link problems since the application contains static paths, such in images or tags, I have to copy all files and folder related to my PHP application from Computer A to the same path in Computer B. Unfortunately, Computer B only has drive C while Computer A has drive D and the files of my PHP application is located in 'D:\xampp\htdocs' in Computer A.
OK, now I have to create drive D in computer B. At first, I tried to create a second partition in Computer B by using PowerQuest Partition Magic 8, but somehow Partition Magic doesn't run in Computer B. I have tried to reinstall it but it still doesn't run. So, another alternative is to create a virtual drive. That is what I did. I created a virtual drive by running the 'subst' command in Command Prompt. The virtual drive is D and it refers to a directory, which is 'C:\Virtual'.
After I have drive D in Computer B, I installed XAMPP there. The installation was successful. Now, I also have 'D:\xampp\htdocs' in Computer B. However, when I ran the Apache, MySQL, or Filezilla service, I receive an error message "Error 3: The system cannot find the file specified.". In Computer B, there is no IIS or process using the port 80. What should I do? Please help me.
Many thanks in advance,
Haris
I hope this doesn't constitute cross-posting, here goes...
Subst doesn't instantiate a mount globally, or within the System User / NT Authority, so the server (apache) cannot access it. Apache accesses via the system account, and so it cannot see a subst mount point (so-called).
Following from this: http://msdn.microsoft.com/en-us/library/aa363908%28v=VS.85%29.aspx
...it seems you can instantiate a subst globally via either the win api or possibly directly in the registry using the DefineDosDevice function or method.
Any way you try to do a subst, even using something such as RunAsSystem to attempt to apply the subst command within the system-user context, will fail to produce a viable result.
However, I found that by creating the DosDevice in the registry I have a viable 'subst' mount that apache/mysql/php-win can use. You can also find ways of doing it via wmi, vb, c+, etc, and I do not know if (I doubt) the registry method is directly the same, but here it is...
Example, I want: subst S: C:\PortableUSB
asA.reg file...
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"S:"="\\??\\C:\\PortableUSB"
Or, in the registry it will look like this (so you can manually add it this way)...
A String Name of "S:" (without the quotes. Use your preferred DriveLetter, of course)
This String's Value is "\??\C:\PortableUSB" (without the quotes. Use your own path, of course)
Requires a restart. The subst is persistent and available globally. I do not yet know how reliable it is, but I am using it with success so far.
TwoHawks

Resources