Jump to content

Cant reat desktop icons placement with runas


E1M1
 Share

Recommended Posts

I am trying to save icons placement on desktop to conf file but problem is that when I use runas to run my exe under diferent user, then it wont write anything in conf file. I also found that if i run it under current user, it can save desktop icon locations to conf file with out problem.

Any ideas how to make that exe work with runas? or why it dont work with other user?

I am running following code under SYSTEM.

it gets the nr of icons but not names

If I run it under "User" then it can read icon names but it don't have permission to write file on disk.

#include <GuiListView.au3>

Global $sConfig_Name

Opt("WinTitleMatchMode", 3)
Opt("TrayIconHide", 1)
_Save_Config()
exit

Func _Save_Config()
    $sConfig_Name = @scriptdir & "\desktopconf.conf"
    _Save_Locations_Desktop()
EndFunc   ;==>_Save_Config

Func _Save_Locations_Desktop()
    _Write_Locations(ControlGetHandle("Program Manager", "", "SysListView321"))
EndFunc   ;==>_Save_Locations_Desktop

Func _Write_Locations($hExplorer_List)
    MsgBox(0,0,_GUICtrlListView_GetItemCount($hExplorer_List))
    For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
        Local $sKey_Name = _GUICtrlListView_GetItemText($hExplorer_List, $i)
        MsgBox(0,0,$sKey_Name)
        Local $aPos = _GUICtrlListView_GetItemPosition($hExplorer_List, $i)
        Local $sValue_Pos = $aPos[0] & ":" & $aPos[1]
        IniWrite($sConfig_Name, "Desktop", $sKey_Name, $sValue_Pos)
    Next
EndFunc   ;==>_Write_Locations

Func _Restore_Config()
    $sConfig_Name = @ScriptDir & "\desktopconf.conf"
    _Set_Positions(ControlGetHandle("Program Manager", "", "SysListView321"))
EndFunc   ;==>_Restore_Config

Func _Set_Positions($hExplorer_List)
    For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
        _GUICtrlListView_SetItemPosition($hExplorer_List, $i, @DesktopWidth, @DesktopHeight + 100 * $i)
    Next
    For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
        Local $sIcon_Name = _GUICtrlListView_GetItemText($hExplorer_List, $i)
        Local $sPos_Saved = IniRead($sConfig_Name, "Desktop", $sIcon_Name, "")
        If $sPos_Saved <> "" Then
            Local $aPos = StringSplit($sPos_Saved, ":")
            _GUICtrlListView_SetItemPosition($hExplorer_List, $i, $aPos[1], $aPos[2])
        EndIf
    Next
EndFunc   ;==>_Set_Positions

edited

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...