gcue Posted July 31, 2008 Share Posted July 31, 2008 (edited) i am running a checks to see if there are shortcuts to given applications in a users startup folder or on teh machines hklocal machine (startup registry) heres an example of one: this function checks if an application is set for startup - a checkmark indicates if the application is set for startup $cuser = RegRead("\\" & $asset & "\hkey_local_machine\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser") $currentuser = StringSplit($cuser, "\") If @error Then MsgBox(0, "Startup", "Does not have a primary user defined in registry. Cannot check userprofile startup directory.") Return EndIf $currentuser_search = FileFindFirstFile("\\" & $asset & "\c$\documents and settings\" & $currentuser[2] & "\start menu\programs\startup\*.lnk") While 1 $currentuser_file = FileFindNextFile($currentuser_search) $currentuser_shortcutpath = FileGetShortcut("\\" & $asset & "\c$\documents and settings\" & $currentuser[2] & "\start menu\programs\startup\" & $currentuser_file) If @error Then ExitLoop If $currentuser_shortcutpath[0] = "c:\blp\wintrv\wintrv.exe" Then GUICtrlSetState($check_Bloomberg, $GUI_CHECKED) EndIf WEnd FileClose($currentuser_search) this function checks if an application is set for startup - a checkmark indicates if the application is set for startup Func Startup_Update($asset) If GUICtrlRead($check_Bloomberg) = 1 Then If Not FileExists("\\" & $asset & "\c$\blp\wintrv\wintrv.exe") Then MsgBox(0, "Startup", "Bloomberg is not installed on this machine.") GUICtrlSetState($check_Bloomberg, $GUI_UNCHECKED) Else RegWrite("\\" & $asset & "\hkey_local_machine\software\microsoft\windows\currentversion\run", "Bloomberg", "REG_SZ", '"c:\blp\wintrv\wintrv.exe"') EndIf Else RegDelete("\\" & $asset & "\hkey_local_machine\software\microsoft\windows\currentversion\run", "Bloomberg") EndIf Currently, i am only able to delete the startup reg entry from HKLM-id like to be able to delete the .lnk file from the users startup if the user decides to uncheck/disable the application from startup. - not sure how to do this. hope this make sense. any help would be appreciated Edited July 31, 2008 by gcue Link to comment Share on other sites More sharing options...
enaiman Posted July 31, 2008 Share Posted July 31, 2008 You have to associate the shortcut name with its target (maybe create a 2 dimensional array where 1 element is the shortcut name and the other is the target). Once you have this done, all you have to do is to use FileDelete to get rid of the shortcut. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
gcue Posted August 1, 2008 Author Share Posted August 1, 2008 how do i create that array? thank you for your help Link to comment Share on other sites More sharing options...
enaiman Posted August 1, 2008 Share Posted August 1, 2008 FileGetShortcut returns an array whose element [0] is exactly the target path (what you're looking for). After you run this command you will have the shortcut (*.lnk) file associated with the path (element [0]) - all you have to do is to put these 2 values into an array and repeat for the next shortcut. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
gcue Posted August 1, 2008 Author Share Posted August 1, 2008 ok thats the part i dont get.. "put these values into an array" Link to comment Share on other sites More sharing options...
enaiman Posted August 6, 2008 Share Posted August 6, 2008 I don't know why it is so difficult ... Dim $LNKArray[50][2] ;for a max of 50 shortcuts (can be more) Dim $i = 0 While 1 $currentuser_file = FileFindNextFile($currentuser_search) $currentuser_shortcutpath = FileGetShortcut("\\" & $asset & "\c$\documents and settings\" & $currentuser[2] & "\start menu\programs\startup\" & $currentuser_file) If @error Then ExitLoop Else $LNKArray[$i][0] = $currentuser_file $LNKArray[$i][1] = $currentuser_shortcutpath $i += 1 EndIf If $currentuser_shortcutpath[0] = "c:\blp\wintrv\wintrv.exe" Then GUICtrlSetState($check_Bloomberg, $GUI_CHECKED) EndIf WEnd This way you will have $LNKArray[1][0] = shortcut name $LNKArray[1][1] = the path to the file you need to delete / or not and so on ... SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now