Houdini 16 on Windows 7, Python Ctype not returning expected value

   2913   2   0
User Avatar
Member
5 posts
Joined: April 2008
Offline
I am not sure if anybody has a fix for this but it looks like the following python code does not return anything, and specifically in
-houdini 16 windows 7
it seems to work fine in houdini 15 and windows 7, or houdini 16 in windows 10, where it returns the full user name of the person logged in.
Any help would be appreciated


import ctypes

def get_display_name():
    GetUserNameEx = ctypes.windll.secur32.GetUserNameExW
    NameDisplay = 3

    size = ctypes.pointer(ctypes.c_ulong(0))
    GetUserNameEx(NameDisplay, None, size)

    nameBuffer = ctypes.create_unicode_buffer(size.contents.value)
    GetUserNameEx(NameDisplay, nameBuffer, size)
    return nameBuffer.value

Thank you
User Avatar
Member
326 posts
Joined: Jan. 2013
Offline
I propose such a solution.
To save a script somewhere on a disk and already from a disk through subprocesses to cause it.

import ctypes

def get_display_name():
    GetUserNameEx = ctypes.windll.secur32.GetUserNameExW
    NameDisplay = 3

    size = ctypes.pointer(ctypes.c_ulong(0))
    GetUserNameEx(NameDisplay, None, size)

    nameBuffer = ctypes.create_unicode_buffer(size.contents.value)
    GetUserNameEx(NameDisplay, nameBuffer, size)
    return nameBuffer.value

print get_display_name()


Function call code
import subprocess

houdini_py = '%s\python27\python.exe' % hou.expandString("$HFS")
file_path = r'C:\get_display_name.py'
p = subprocess.Popen([houdini_py, file_path], stdout=subprocess.PIPE, shell=True)
print p.communicate()[0]
User Avatar
Member
5 posts
Joined: April 2008
Offline
Thank you for the answer, I ended up just calling a command line that is compatible with windows7 and windows10
import subprocess
cmd = ['Whoami', '/FQDN']
process = subprocess.Popen(cmd,stdout=subprocess.PIPE, shell=True)
name = process.stdout.read().split(',')[0].split('CN=')[-1]

Cheers
Aldo
  • Quick Links