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
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9253
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Application:cDirectory Windows 8

Mensaje 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,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9253
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Application:cDirectory Windows 8

Mensaje 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
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Avatar de Usuario
orangesocks
Mensajes: 59
Registrado: Jue May 05, 2011 3:28 pm

Application:cDirectory Windows 8

Mensaje 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
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
Oleg
Mensajes: 474
Registrado: Mié Jun 07, 2006 3:45 pm

Application:cDirectory Windows 8

Mensaje 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;
}
....
Oleg
Mensajes: 474
Registrado: Mié Jun 07, 2006 3:45 pm

Application:cDirectory Windows 8

Mensaje por Oleg »

This code works in case:
only one drive letter mapped to one UNC path
Avatar de Usuario
orangesocks
Mensajes: 59
Registrado: Jue May 05, 2011 3:28 pm

Application:cDirectory Windows 8

Mensaje por orangesocks »

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

Attached files TestUNCToLocalPath.zip (3.8 KB)Â
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje por emeasoft »

Many Thanks for the help Giuseppe and Oleg!
It worked very well!
Regards,
Juliano
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje 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
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje 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
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje 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
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje por emeasoft »

Lalin:
Win 7:
F:BACKUP
F:BACKUPTESTE.exe
Win 8:
linuxsistemaBACKUP
linuxsistemaBACKUPTESTE.exe
Regards
Mário Angelini
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje por joselalinf »

Mário,
now can you show me some code to see what you want to do?
Regards,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Application:cDirectory Windows 8

Mensaje 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
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje 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
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje 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
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje 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
--
joselalinf
Mensajes: 291
Registrado: Jue Ene 31, 2013 1:10 pm

Application:cDirectory Windows 8

Mensaje por joselalinf »

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