In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Application:cDirectory Windows 8

Xailer professional forum in English
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Tue Oct 22, 2013 7:14 pm

Hello Xailers,
When I try to execute my program with admin rights from a network place it returns a different Application:cDirectory...
eg.: Without admin rights it returns F:TestsExample
With admin rights it returns TestesExample or
linuxSistemaTestsExample
Is this an error? How can I make it return F:TestsExample when executed with admin rights?
Thanks in advance,
Juliano
User avatar
ignacio
Site Admin
Posts: 8545
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Application:cDirectory Windows 8

Postby ignacio » Wed Oct 30, 2013 12:26 pm

emeasoft escribió el mar, 22 octubre 2013 19:14
Hello Xailers,
When I try to execute my program with admin rights from a network place it returns a different Application:cDirectory...
eg.: Without admin rights it returns F:TestsExample
With admin rights it returns TestesExample or
linuxSistemaTestsExample
Is this an error? How can I make it return F:TestsExample when executed with admin rights?
Thanks in advance,
Juliano

Xailer uses the API function GetModuleFileName(). Check this link for further information:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms68 3197(v=vs.85).aspx

Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Wed Oct 30, 2013 1:36 pm

Hello Ignacio,
So, cant I get a not UNC patch when executing a program as admin on a network from a windows 8 pc?
Will it always return the UNC path? eg.: computeruserdir instead of X:dir
TIA,
Juliano
User avatar
ignacio
Site Admin
Posts: 8545
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Application:cDirectory Windows 8

Postby ignacio » Wed Oct 30, 2013 1:44 pm

emeasoft escribió el mié, 30 octubre 2013 13:36
Hello Ignacio,
So, cant I get a not UNC patch when executing a program as admin on a network from a windows 8 pc?
Will it always return the UNC path? eg.: computeruserdir instead of X:dir
TIA,
Juliano

I believe that is not possible since many drive mapping can have the same path. But I really do not know. That is a specific OS issue.
Regards
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
User avatar
orangesocks
Posts: 55
Joined: Thu May 05, 2011 3:28 pm

Application:cDirectory Windows 8

Postby orangesocks » Wed Oct 30, 2013 2:28 pm

Hello Juliano,
You can try with this function.
I use it with my console apps. On Win7 it works OK but I don't have Win8 so I don't know if it fails.
FUNCTION GetAppPath()
LOCAL cFileName AS CHAR
cFileName := hb_argv( 0 )
RETURN Left( cFileName, RAt( "", cFileName ) )
HTH Regards, Giuseppe
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Thu Oct 31, 2013 11:14 am

Hello Ignacio and Giuseppe, thanks for your help!
Giuseppe, this function did not work on windows 8... it still returns the unc path.
Any of you know if there is a way to translate the unc path to a path with drive letter?
TIA,
Juliano
Oleg
Posts: 474
Joined: Wed Jun 07, 2006 3:45 pm

Application:cDirectory Windows 8

Postby Oleg » Thu Oct 31, 2013 12:30 pm

Juliano,
See below.
Maybe not so good code, but working
Regards, Oleg
func UNC2Mapped(cUncPath)
local cMapped, cUnc, i
cMapped:=''
for i:=asc('F') to asc('Z')
cUnc:=Mapped2Unc(chr(i)+':')
if !empty(cUnc).and.cUncPath=cUnc
cMapped:=stuff(cUncPath,1,len(cUnc),chr(i)+':')
exit
endif
next
return cMapped
....
#include "windows.h"
#include "hbapi.h"
HB_FUNC( MAPPED2UNC ){
char *path = hb_parc(1), *unc;
UNIVERSAL_NAME_INFO *puinfo;
char buf2[300];
DWORD size=300;
unc = hb_xgrab(254);
if (!path || !unc){
hb_ret();
hb_xfree(unc);
return;
}
//check its valid
if (GetFileAttributes(path) == 0xffffffff){
hb_ret();
hb_xfree(unc);
return;
}
//if already unc then just copy it over
if (path[0] == '' && path[1] == '') {
strcpy(unc,path);
hb_retc(unc);
hb_xfree(unc);
return;
}
//we need to find out if its a network drive
//if so we need to get the UNC path cos the
if (WNetGetUniversalName(path, UNIVERSAL_NAME_INFO_LEVEL, buf2, &size)
== NO_ERROR)
{
//it is a network drive so lets get the UNC path
puinfo = (UNIVERSAL_NAME_INFO*)buf2;
strcpy(unc,puinfo->lpUniversalName);
hb_retc(unc);
hb_xfree(unc);
return;
}
hb_ret();
hb_xfree(unc);
return;
}
....
Oleg
Posts: 474
Joined: Wed Jun 07, 2006 3:45 pm

Application:cDirectory Windows 8

Postby Oleg » Thu Oct 31, 2013 12:49 pm

This code works in case:
only one drive letter mapped to one UNC path
User avatar
orangesocks
Posts: 55
Joined: Thu May 05, 2011 3:28 pm

Application:cDirectory Windows 8

Postby orangesocks » Thu Oct 31, 2013 1:12 pm

Hello Juliano,
You can also use the registry. See attached example.
HTH Giuseppe

Attached files TestUNCToLocalPath.zip (3.8 KB)Â
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Wed Nov 06, 2013 1:38 pm

Hello,
We are having the following problem with Windows 8 when running as administrator on a server on the network:
--------------------------------------------
Windows XP e Windows 7:
Application:cDirectory = F:XAILER
Application:CurrentDrive() = F:
HB_Curdrive() = F
CurDir() = XAILER
--------------------------------------------
Windows 8:
Application:cDirectory = linuxxailer
Application:CurrentDrive() = A:
HB_Curdrive() = A
CurDir() = linuxxailer
If we use the LEN(Directory("F:XAILER*.*")) it returns 0.
--------------------------------------------
We understand that the returns should be the same, regardless the OS.
Thanks
Mário Angelini
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Wed Nov 06, 2013 2:05 pm

Mário,
> If we use the LEN(Directory("F:XAILER*.*")) it returns 0.
¿Doesn't it work just using Len( Directory( Application:cDirectory ) )?
AFAIK the Harbour file system should manage UNC paths as it uses the OS
native file system.
Regards,
José Lalí­n
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Wed Nov 06, 2013 2:17 pm

Lalin
Len( Directory( Application:cDirectory ) ) retorna correto, mas precisamos em muitas
rotinas saber qual o Application:CurrentDrive() ou HB_Curdrive() e está retornando
diferente do Win 7/XP.
Entendemos que deverá retornar sempre a mesma coisa, independente do sistema operacional.
Mário Angelini
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Wed Nov 06, 2013 3:32 pm

Mário,
sorry, I didn't understood the problem at first read. Maybe these Harbour
functions can help you:
hb_ProgName()
hb_DirBase()
hb_CWD()
Regards,
José Lalí­n
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Wed Nov 06, 2013 8:14 pm

Mário,
¿can you tell me what shows this code in both W7 and W8?
MsgInfo( Application:cDirectory + CRLF + Application:cFilename )
Regards,
José Lalí­n
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Wed Nov 06, 2013 8:58 pm

Lalin:
Win 7:
F:BACKUP
F:BACKUPTESTE.exe
Win 8:
linuxsistemaBACKUP
linuxsistemaBACKUPTESTE.exe
Regards
Mário Angelini
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Wed Nov 06, 2013 9:49 pm

Mário,
now can you show me some code to see what you want to do?
Regards,
José Lalí­n
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Thu Nov 07, 2013 11:49 am

Hello,
Eg:
VolSerial("F:")
We have many routines that use:
Application:cDirectory
Application:CurrentDrive()
HB_Curdrive()
CurDir(
Our users that use network, have terminals with Win XP/7/8, all together on the network.
The return of this functions should be all the same.
Eg.:
An application on a terminal with windows 7 returns:
Application:CurrentDrive() = F:
HB_Curdrive() = F
--------------------------------------------
The same application on windows 8 returns:
Application:CurrentDrive() = A:
HB_Curdrive() = A
It is visible that this is not right.
Regards
Mário Angelini
User avatar
emeasoft
Posts: 1062
Joined: Wed Apr 01, 2009 4:12 pm
Location: emeasoft
Contact:

Application:cDirectory Windows 8

Postby emeasoft » Thu Nov 07, 2013 1:23 pm


WITH OBJECT TRegistry():Create()
//Desativa UAC - Requer reinicialização do equipamento
//Disable UAC - Requires restart of equipment
:Root:=HKEY_LOCAL_MACHINE
IF :OpenKey("Software")=0
:CreateKey("Microsoft","Software")
:CreateKey("Windows","Microsoft")
:CreateKey("CurrentVersion","Windows")
:CreateKey("Policies","CurrentVersion")
:CreateKey("System","Policies")
:CloseKey(.T.)
IF :OpenKey("SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem") = 0
IF :GetNumeric( "EnableLUA" )=1
:SetNumeric("EnableLUA",0)
ENDIF
ENDIF
:CloseKey(.T.)
ENDIF
:CloseKey(.T.)
:Flush(.T.)
:Destroy(.T.)
END

Resolvido / Resuelto / resolved
Regards
Mário Angelini
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Thu Nov 07, 2013 1:35 pm

Mário,
> It is visible that this is not right.
From an OS point of view the last is the correct. The UNC paths should
(and must) hide the real path in terms of security.
Anyhow, I found some info explaining how to do it in Win8. I will try to
find some spare time tonight to do it.
Regards,
José Lalí­n
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Thu Nov 07, 2013 1:48 pm

Mário,
many network administrators disable the access to the registry so be
careful and check that function runs correctly in every system.
Regards,
José Lalí­n
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Thu Nov 07, 2013 5:28 pm

Mário,
the attached obj includes a function to convert an UNC path to a local path.
UNCToPath( cUNCPath, @nError ) --> cLocalPath
* cUNCPath: the UNC path to convert
* nError: error code (Optional).
-1 internal error
0 success
any other value: OS code
Example:
LOCAL nErr := 0
MsgInfo( UNCToPath( Application:cDirectory ) )
MsgInfo( UNCToPath( Application:cDirectory, @nErr ) )
IF nErr != 0
MsgSysError( nErr )
ENDIF
I could not test it in a real scenario yet. Let me know if it works.
Regards,
José Lalí­n
--
joselalinf
Posts: 291
Joined: Thu Jan 31, 2013 1:10 pm

Application:cDirectory Windows 8

Postby joselalinf » Thu Nov 07, 2013 6:34 pm

Mário,
I see it while writing this reply.
Regards,
José Lalí­n

Return to “English”