OK. Your code is very close to working. Thank-you for posting it, it is very nice!
First of all, it is important to note that we are using iron python and when calling VC methods we must keep in mind that we python is talking to C# so a few extra steps are involved when dealing with things like lists and dictionaries. When using simple variables such as strings and integers it is not an issue.
Here is a working version of your code.
import ctypes as _ctypes
from ctypes.wintypes import HWND as _HWND, HANDLE as _HANDLE,DWORD as _DWORD,LPCWSTR as _LPCWSTR,MAX_PATH as _MAX_PATH, create_unicode_buffer as _cub
_SHGetFolderPath = _ctypes.windll.shell32.SHGetFolderPathW
from System.Collections.Generic import Dictionary,List
def get(intFolder):
_SHGetFolderPath.argtypes = [_HWND, _ctypes.c_int, _HANDLE, _DWORD, _LPCWSTR]
auPathBuffer = _cub(_MAX_PATH)
exit_code=_SHGetFolderPath(0, intFolder, 0, 0, auPathBuffer)
return auPathBuffer.value
#print get(23)
#print get(2)
userProgramsPath = get(2)
programsPath = get(23)
import fnmatch
import os
dictUserPrograms = Dictionary[str,str]()
for root, dirnames, filenames in os.walk(userProgramsPath):
for filename in fnmatch.filter(filenames, '*.lnk'):
#print filename
dictUserPrograms[os.path.join(root, filename)] = filename.replace(".lnk","")
#print dictUserPrograms
vc.savePayloadFile("startmenu.xml", dictUserPrograms, 1)
So the first thing I needed to add was the line:
from System.Collections.Generic import Dictionary,List
(actually we probably don't need to import List here, but we might need it for some other methods)
then when declaring the dictionary we change
dictUserPrograms = {}
to
dictUserPrograms = Dictionary[str,str]()
Now our dictionary is in a format that c# can understand when we pass it back in the vc.savePayloadFile method.