Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS Shares

Status
Not open for further replies.

Crisps

Programmer
Sep 28, 2006
26
0
0
US
hi,

Not sure if this is the correct forum, but I am intending on implementing the answer to this in C++ if necessary.

I have a script which needs to 'cd' to a directory in order to run some commands from there (clearcase requires that that is the current directory, crap I know). You cannot have a UNC directory as the current working directory under DOS.

this directory is mapped to a share \\127.0.0.1\views on every machine. However the 'real' directory could be anywhere e.g. c:\local_views or d:\myviews

Is there any way I can query the \\127.0.0.1\views and get from it the relevant local directory e.g. d:\myviews.

If I there is a windows API for this I can write a utility to do this in C++, although I am open to any suggestions.

Thanks,

 
this did the trick

Code:
	int iRc = 1;
	HKEY hKey = NULL;
	
	if(argc == 2)
	{
		if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\Shares", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
		{
			char szDescription[2048];
			DWORD dwSize = sizeof(szDescription);
			if(RegQueryValueEx(hKey, argv[1], NULL, NULL, (BYTE*)szDescription, &dwSize) == ERROR_SUCCESS)
			{
				//parse description
				char* ptr = szDescription;
				while(strlen(ptr))
				{	
					if(strnicmp(ptr, "Path", 4) == 0)
					{
						printf("%s", ptr + 5);
						iRc = 0;
						break;
					}
					ptr += strlen(ptr) + 1;	
				}

				if(iRc)
				{
					printf("Share found but not associated with a path\n");
				}
			}
			else 
			{
				printf("could not read registry value for share <%s>, Error <%d>", argv[1], GetLastError());
			}

			RegCloseKey(hKey);
		}
		else
		{
			printf("Could not open key HKLM\\SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\Shares for reading, error <%d>\n", GetLastError());
		}
	}
	else
	{
		printf("Usage: GetDirFromShare <share name>\n");
	}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top