How to check user permissions

Moderator: Rathinagiri

Post Reply
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

How to check user permissions

Post by hmgchang »

Dear Frens,
Marhaban ya Ramadhan

How to code for checking user permission for a folder in order to create/write a file/s....
Is there anyway to change/get the write permission on a folder.
It's on win10 os
TIA

Best rgds
Chang
Last edited by hmgchang on Sat May 19, 2018 9:27 pm, edited 1 time in total.
Just Hmg It !
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: How to check user permussions

Post by KDJ »

Chang

Without coding in C, you can check if you have permission to write to the directory by trying to create a temporary file in this directory.
Example:

Code: Select all

#include "fileio.ch"
#include "hmg.ch"

FUNCTION Main()
  LOCAL cDir := "C:\Program Files"

  IF HB_DirExists(cDir)
    MsgBox(cDir + CRLF + CRLF + If(IsDirWritable(cDir), "You can write in this directory.", "You have not permissions to write in this directory!"))
  ELSE
    MsgBox(cDir + CRLF + CRLF + "Directory not found!")
  ENDIF

RETURN NIL

FUNCTION IsDirWritable(cDir)
  LOCAL cFileName
  LOCAL nFileHandle

  nFileHandle := HB_fTempCreate(cDir, NIL, FC_NORMAL, @cFileName)

  IF nFileHandle != F_ERROR
    fClose(nFileHandle)
    fErase(cFileName)
    RETURN .T.
  ENDIF

RETURN .F.
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: How to check user permissions

Post by hmgchang »

Yes and thanks KDJ,
what I don't understand is, I may copy files to my c:\, but
within hmgExe, I can not save a text file by hb_Memowrit to my c:\

any suggestion ?
TIA

best rgds,
Chang
Just Hmg It !
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: How to check user permissions

Post by apais »

No program is alowed to write to the root folder since win 7
Angel Pais
Web Apps consultant/architect/developer.
HW_apache (webserver modules) co-developer.
HbTron (Html GUI for harbour desktop hybrid apps) co-developer.
https://www.hbtron.com
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: How to check user permissions

Post by bpd2000 »

1. If you run KDJ's program as Administrator in windows then Program is allowed to write to the root folder
Untitled.png
Untitled.png (6.81 KiB) Viewed 4526 times
Or
You can get applications to write to Program Files by changing the folder's security settings.

1. Go to properties and select the Security tab.
2. Click Advanced.
Image
3. Change ownership to your own account instead of TrustedInstaller, and let it propagate. This allows you to add yourself to the list of principals.
4. Click 'Add' and type your username, press 'Check names' and it auto-corrects.
Now you can add 'Full control' for your username, and all applications you run should be able to write to this folder and its sub folders.
Or
Always Run a Program as Administrator in Windows:
Create shortcut of your program, Select shortcut, right click with mouse Go to the properties, and there you will find a button labeled “Advanced.” Click on it. Check the “Run as administrator” box, and then press OK. From now on, this shortcut icon will run the program with administrator's privileges all the time
Attachments
Untitled2.png
Untitled2.png (29.18 KiB) Viewed 4524 times
BPD
Convert Dream into Reality through HMG
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: How to check user permissions

Post by hmgchang »

Dear Apais,
No program is alowed to write to the root folder since win 7
but I can copy/paste files to the c:\ with win explorer

Dear Bpd2000,
Thanks for the tips
1. Can we set the Administrators rights to the hmg Exe ?
2. Wil the rights remain if we rebuild the Exe ?

TIA

best rgds,
Chang
Just Hmg It !
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: How to check user permissions

Post by dragancesu »

User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: How to check user permissions

Post by bpd2000 »

hmgchang wrote: Sun May 20, 2018 9:54 pm Dear Apais,
No program is alowed to write to the root folder since win 7
but I can copy/paste files to the c:\ with win explorer

Dear Bpd2000,
Thanks for the tips
1. Can we set the Administrators rights to the hmg Exe ?
2. Wil the rights remain if we rebuild the Exe ?

TIA

best rgds,
Chang
I have not tested / knowledge but it can be done through necessary changes / addition in Manifest
Claudio / Gfilatov / Rathinagiri may help you

Code: Select all

<requestedExecutionLevel
level="asInvoker|highestAvailable|requireAdministrator"
uiAccess="true|false"/>
https://msdn.microsoft.com/en-us/library/bb756929.aspx

Another way is Pack your app into WinRar SFX with silent mode + admin request mode.
I have tested and is working smart
BPD
Convert Dream into Reality through HMG
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: How to check user permissions

Post by bpd2000 »

Bpd2000
1. Can we set the Administrators rights to the hmg Exe ?
2. Wil the rights remain if we rebuild the Exe ?
Finally I have managed to generate Manifest file to run app with Admin rights
You have to add reference of manifest file in RC file
Finally working example of app run as Administrators rights
My OS is Win-10, request other users to check it is working Ok or not
Attachments
Permission.rar
(1.21 MiB) Downloaded 188 times
BPD
Convert Dream into Reality through HMG
Post Reply