Page 1 of 1

DWORD registry value - prohibiting an executable

Published: February 6, 2017 - 10:34 AM
by gaelds
Good morning,
I'm having trouble adding a DWORD value to the registry; I get the following message when running session-setup:

CRITICAL ValueError: Could not convert the data to the specified type.


It's the same with the values ​​1 or 0x00000001.

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
import time
import os

uninstallkey = []

def GetUserName():
    return os.getenv('USERNAME')

def install():
    print('Installation de DisallowRun')

def session_setup():
    utilisateur = GetUserName()
    if(utilisateur == "eleve"):
        registry_set(HKEY_CURRENT_USER,r'Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/','DisallowRun','0x00000001',type=REG_DWORD)
        registry_set(HKEY_CURRENT_USER,r'Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/DisallowRun','1','shutdown.exe',type=REG_SZ)


Re: DWORD registry

Published: February 6, 2017 - 10:46 AM
by htouvet

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    print('Installation de DisallowRun')

def session_setup():
    if (get_current_user() == "eleve"):
        registry_set(HKEY_CURRENT_USER,r'Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/','DisallowRun',1,type=REG_DWORD)
        registry_set(HKEY_CURRENT_USER,r'Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/DisallowRun','1','shutdown.exe',type=REG_SZ)

Re: DWORD registry

Published: February 6, 2017 - 10:48 AM
by gaelds
I just found another registry_set syntax in a message on the wapt mailing list and apparently it works:

Code: Select all

registry_set(HKEY_CURRENT_USER,r'Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/', r'DisallowRun', 1, REG_DWORD)
Even after the shutdown.exe program is still not blocked for the student user, that's another problem...

Re: Prohibition of an executable

Published: February 6, 2017 - 11:21
by gaelds
Ah sorry, our previous messages must have crossed paths, otherwise I tested another method with iCalcs to block access to shudown.exe.

Code: Select all

def session_setup():
    if (get_current_user() == "eleve"):
        print('interdiction de shutdown.exe pour eleve')
        run(r'takeown /F %windir%\system32\shutdown.exe')
        run(r'icacls %windir%\system32\shutdown.exe /deny eleve:D')
The command lines work in manual mode, but in session-setup, it has no effect, nor does it produce an error message.