Página 1 de 2

Application:cDirectory Windows 8

Publicado: Mar Oct 22, 2013 7:14 pm
por emeasoft
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

Application:cDirectory Windows 8

Publicado: Mié Oct 30, 2013 12:26 pm
por ignacio
emeasoft escribió el mar, 22 octubre 2013 19:14Hello 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 ... sktop/ms68 3197(v=vs.85).aspx

Regards,

Application:cDirectory Windows 8

Publicado: Mié Oct 30, 2013 1:36 pm
por emeasoft
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

Application:cDirectory Windows 8

Publicado: Mié Oct 30, 2013 1:44 pm
por ignacio
emeasoft escribió el mié, 30 octubre 2013 13:36Hello 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

Application:cDirectory Windows 8

Publicado: Mié Oct 30, 2013 2:28 pm
por orangesocks
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

Application:cDirectory Windows 8

Publicado: Jue Oct 31, 2013 11:14 am
por emeasoft
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

Application:cDirectory Windows 8

Publicado: Jue Oct 31, 2013 12:30 pm
por Oleg
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;
}
....

Application:cDirectory Windows 8

Publicado: Jue Oct 31, 2013 12:49 pm
por Oleg
This code works in case:
only one drive letter mapped to one UNC path

Application:cDirectory Windows 8

Publicado: Jue Oct 31, 2013 1:12 pm
por orangesocks
Hello Juliano,
You can also use the registry. See attached example.
HTH Giuseppe

Attached files TestUNCToLocalPath.zip (3.8 KB)Â

Application:cDirectory Windows 8

Publicado: Vie Nov 01, 2013 6:26 pm
por emeasoft
Many Thanks for the help Giuseppe and Oleg!
It worked very well!
Regards,
Juliano

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 1:38 pm
por emeasoft
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

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 2:05 pm
por joselalinf
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

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 2:17 pm
por emeasoft
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

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 3:32 pm
por joselalinf
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

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 5:35 pm
por emeasoft
Lalin,
Não resolveu.
Continua com o mesmo problema.
Abraços.
Mário

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 8:14 pm
por joselalinf
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

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 8:58 pm
por emeasoft
Lalin:
Win 7:
F:BACKUP
F:BACKUPTESTE.exe
Win 8:
linuxsistemaBACKUP
linuxsistemaBACKUPTESTE.exe
Regards
Mário Angelini

Application:cDirectory Windows 8

Publicado: Mié Nov 06, 2013 9:49 pm
por joselalinf
Mário,
now can you show me some code to see what you want to do?
Regards,
José Lalí­n

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 11:49 am
por emeasoft
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

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 1:23 pm
por emeasoft

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

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 1:35 pm
por joselalinf
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

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 1:48 pm
por joselalinf
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

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 5:28 pm
por joselalinf
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
--

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 6:08 pm
por emeasoft
the attached obj:
Nothing attached
Mário

Application:cDirectory Windows 8

Publicado: Jue Nov 07, 2013 6:34 pm
por joselalinf
Mário,
I see it while writing this reply.
Regards,
José Lalí­n