Hi I have the follow VBS that runs without any problem if I put it in a .vbs file and run it.
Dim objshell
Set objshell = CreateObject("Shell.Application")
objshell.NameSpace("C:\Temp").CopyHere(objshell.NameSpace("C:\Temp\Test.zip").Items())
Set objshell = Nothing
But if I cut and paste it into a script task in SSBI 2008, it runs with the error
Error: 0x1 at Script Task: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80020003): Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSetComplex(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase)
at ST_a4312d30d99b4cc4b02a2198afbc77d9.vbproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Task failed: Script Task
I believe there has to be some configuration inside SSBI to be set instead of just running by default in order to make this working. It doesn't matter if I will have to use C# instead. But just dont ask me to use and install any 3rd party stuff. The system is running Windows 7 with .NET 4.5 installed.
Please help! Thank you!
I figured out the configuration but it is somewhat complicate.
Open your script task, Edit Script. When the script editing window opens, place the above script to Sub Main with a little changes:
Dim objshell
becomes
Dim objshell As Shell
Go to Project->st_xxxxx Properties, Signing, tick sign the assembly, select New, type any file name, untick Protect my file with a password.
Go to References, Add, COM, select Microsoft Shell Controls And Automation, OK.
** You should see a popup saying No template information found..., just ignore that. **
Highlight the Microsoft Shell Controls you just added and look at the bottom right properties section, make sure "Strong Name" is True.
(if you haven't done step 2., this should be False, redo step 2 and make sure this is True)
Open My Computer and go to the path of the generated Microsoft Shell Controls dll (see the highlighted Path, usually it is C:\Users\xxxxxxx\AppData\Local\Temp\SSIS\yyyyyyyyyyyyyyyyy\obj\Debug\Interop.Shell32.dll). Copy it to somewhere else (its because the original path yyyyyyyyyyyyyy is randomly generated everytime you edit your script, causing that the signed dll gone everytime).
Back to the Project->st_xxxxx Properties, remove the highlighted Microsoft Shell Controls. Click Add, Browse, select the Interop.Shell32.dll you just copied, OK. Again, make sure the Strong Name property is True. If not, redo from step 2.
Still at References, under Imported namespaces, scroll down to tick the box next to Shell32.
Go to Signing, untick Sign the assembly. Go to Project Explorer on top right, delete the key file (xxxx.snk) you created at step 2 (delete the key file within Project Explorer, not from your folder, make sure it is not included in your Project Explorer anymore or your script task wont run).
Save all and close the Script Editing window.
Locate "gacutil.exe" in your computer. You should have it together with the installation of SSIS. Its under C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64. Type gacutil -i "path of your copied Interop.Shell32.dll in step 5".
e.g. gacutil -i F:\Code\Interop.Shell32.dll
After all these steps, your script task should run without problems. Of course, these steps are needed if you are using other COM references. Let me know if there are some easier ways to do the job. Hope this helps.
Script tasks in SSIS run .NET code, not VBScript code. Just re-write your code in VB.NET using the File
Class and whatever other classes you need.
Alternatively, keep your VBS script and run it using an Execute Process task.
User contributions licensed under CC BY-SA 3.0