How to check user permissions

Moderator: Rathinagiri

Post Reply
User avatar
hmgchang
Posts: 204
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

How to check user permissions

Post by hmgchang » Thu May 17, 2018 10:52 pm

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: 192
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 218 times

Post by KDJ » Fri May 18, 2018 7:54 pm

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: 204
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » Sat May 19, 2018 9:33 pm

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: 273
Joined: Fri Aug 01, 2008 6:03 pm
Location: uruguay
Has thanked: 33 times
Been thanked: 21 times
Contact:

Post by apais » Sat May 19, 2018 10:05 pm

No program is alowed to write to the root folder since win 7

User avatar
bpd2000
Posts: 1005
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 154 times
Been thanked: 66 times

Post by bpd2000 » Sun May 20, 2018 4:37 am

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 209 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 207 times
BPD
Convert Dream into Reality through HMG

User avatar
hmgchang
Posts: 204
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » 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
Just Hmg It !

User avatar
dragancesu
Posts: 535
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 11 times
Been thanked: 95 times

Post by dragancesu » Sun May 20, 2018 10:10 pm


User avatar
bpd2000
Posts: 1005
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 154 times
Been thanked: 66 times

Post by bpd2000 » Mon May 21, 2018 8:00 am

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: 1005
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 154 times
Been thanked: 66 times

Post by bpd2000 » Mon May 21, 2018 9:09 am

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 19 times
BPD
Convert Dream into Reality through HMG

Post Reply