Jump to content

Recommended Posts

Posted (edited)

Hi,

Can this small piece of vbscriot code be easily integrated into an existing AutoIT? Are there any examples of vbscript code converted into AutoIT code on the forum?

Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Const CSIDL_STARTMENU = &HB
Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCurrentUserStartFolder = objShell.NameSpace (CSIDL_STARTMENU)
strCurrentUserStartFolderPath = objCurrentUserStartFolder.Self.Path
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path


If objFSO.FileExists(strCurrentUserStartFolderPath & "\Programs\Accessories\Windows Explorer.lnk") Then
Set objFolder = objShell.Namespace(strCurrentUserStartFolderPath & "\Programs\Accessories")
Set objFolderItem = objFolder.ParseName("Windows Explorer.lnk")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
Next
End If

Thanks

Edited by Briandr
  • Moderators
Posted

VBScript translates pretty easily, something like this:

Const $CSIDL_COMMON_PROGRAMS = "&H17"
Const $CSIDL_PROGRAMS = "&H2"
Const $CSIDL_STARTMENU = "&HB"

$oShell = ObjCreate("Shell.Application")
$oFSO = ObjCreate("Scripting.FileSystemObject")
$oCurrentUserStartFolder = $oShell.NameSpace($CSIDL_STARTMENU)
$sCurrentUserStartFolderPath = $oCurrentUserStartFolder.Self.Path
$oAllUsersProgramsFolder = $oShell.NameSpace($CSIDL_COMMON_PROGRAMS)
$sAllUsersProgramsPath = $oAllUsersProgramsFolder.Self.Path


    If $oFSO.FileExists($sCurrentUserStartFolderPath & "\Programs\Accessories\Windows Explorer.lnk") Then
        $oFolder = $oShell.Namespace($sCurrentUserStartFolderPath & "\Programs\Accessories")
        $oFolderItem = $oFolder.ParseName("Windows Explorer.lnk")

        $aVerbs = $oFolderItem.Verbs

            For $verb in $aVerbs
                $sVerb = StringReplace($verb.name, "&", "")
                    If $sVerb = "Unpin from Taskbar" Then $verb.DoIt
            Next
    EndIf

But is there a reason why you want to just unpin it instead of deleting it?

#include <Array.au3>
#include <File.au3>

$Folder = @AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
Local $aArray = _FileListToArray($Folder, "*.lnk", Default, True)

    For $sFile In $aArray
        If StringInStr($sFile, "Windows Explorer") Then
            FileDelete($sFile)
        EndIf
    Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

converter: >link

Snips & Scripts

  Reveal hidden contents

My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted
  On 10/10/2014 at 5:14 PM, MikahS said:

converter: >link

This is 9 years old!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 10/10/2014 at 5:18 PM, guinness said:

This is 9 years old!

 

Time for me to get my eyes checked. :geek:

Snips & Scripts

  Reveal hidden contents

My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted

It might work, but considering the language has changed tenfold, I kind of highly doubt it.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 10/10/2014 at 5:24 PM, guinness said:

I kind of highly doubt it.

Snips & Scripts

  Reveal hidden contents

My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted

Thanks to all have responded! No particular reason for unpinning vs deleting. I hope AutoIT overtakes VB in popularity, maybe it already has. That would be nice. Easier to work with or so it seems :bye:

Posted

Last time I heard VBScript was deprecated and PowerShell was its successor.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

There are 2 functions in that link that don't work, _ArrayCreate and _Iif, both having been removed/replaced, but easy enough to recreate. The convertor isn't 100% accurate anyways, for example it doesn't handle comments that aren't at the start of a line.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

  • Moderators
Posted

VBScript has been dead for a long time, though I admit I still look it up for reference sometimes. It is far easier to convert than PowerShell, what with all the embedded cmdlets

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi JLogan3o13,

When I ran the code you converted from vbscript to AutoIT, if did not work. When I ran it as a vbscript it did work. My next step would be to make this a total separate AutoIT script and not incorporate it as part of another AutoIT script, which I did.

Any ideas?

Thanks

  • Moderators
Posted

The sample I provided was not meant to provide you with a fully functioning script, but an example of how vbscript converts to AutoIt.

As far as "it doesn't work", that doesn't help us much ;) You need to add some error checking to your script so you can figure out at what point it is failing. Take a look at @error in the help file. The link to SetError shows a decent example

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

I am still messing around with getting error checking working on this (new to Autoit), but I read your first reply and if it is easier I just assume delete the lnk. Only thing is I need to delete the lnk for all users, not just current users. When I get an error I'll paste it back.

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
  • Recently Browsing   0 members

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