473,473 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert VBScript to Visual Basic .Net

I have found code that Recycles the Application Pool but it was written in
VBScript can anyone convert this for me to VB.Net?
Thanks!

'Appendix B: Application Pool Recycle script - Save as Recycleap.vbs

'By Default Recycle All App Pools
bRecycleAll = 1
'Delay between each apppool recycle in seconds (if all apppools are being
recycled)
iRecycleDelay = 5

If Wscript.arguments.count = 0 Then
WScript.Echo "Syntax: recycleap server [AppPoolName]"
WScript.Echo
WScript.Echo "Example: recycleap servername DefaultAppPool"
WScript.Quit (0)
Else
strServer = WScript.arguments(0)
If WScript.arguments.count > 1 Then
strAppPoolName = WScript.arguments(1)
bRecycleAll = 0
End If
End If

'Connect to the specified server using WMI
set Locator = CreateObject("WbemScripting.SWbemLocator")
Locator.Security_.AuthenticationLevel = 6
set Service = locator.connectserver(strServer,"root/MicrosoftIISv2")

'Get a collection of WMI apppools
set APCollection = Service.InstancesOf("IISApplicationPool")

If bRecycleAll = 1 Then
'Recycle each apppool returned in the collection with a delay of
iRecycleDelay
For each APInstance in APCollection

WScript.Echo "Recycling " & strServer & "/" & APInstance.Name
APInstance.Recycle

WScript.Echo "Waiting " & iRecycleDelay & " seconds..."
Wscript.Sleep(iRecycleDelay*1000)
Next
Else
'If we're not recycling all apppools find the one that was specified and
recycle it
For each APInstance in APCollection
If UCase(ApInstance.Name) = UCase("W3SVC/AppPools/" &
strAppPoolName) Then
WScript.Echo "Recycling " & strServer & "/" & APInstance.Name
APInstance.Recycle
End If
Next
End If

WScript.Echo "Done!"
May 26 '06 #1
1 11841
WScript is the parsing engine
WScript.echo is the sampe as debug.print

WbemScripting.SWbemLocator apears to be a WMI wrapper to peer into the
application pools. Cerainly you could use createobject in .Net as well,
just that it would be COM Interop.

Everything else is pure VB.

Here is my once over pass at it.

1. Create a new console application in .Net,
2. Add a reference to COM | WBemScripting (Microsoft WMI Scripting V1.2
Library)
Set Copy Local to false
3. Paste in this code
4. Test

Module Module1

'Appendix B: Application Pool Recycle script - Save as Recycleap.vbs>
'By Default Recycle All App Pools
Private bRecycleAll As Boolean = 1
'Delay between each apppool recycle in seconds (if all apppools are being
recycled)
Private iRecycleDelay As Integer = 5

Private strServer As String = String.Empty
Private strAppPoolName As String = String.Empty

'More information can be found at
http://msdn.microsoft.com/library/de...nectserver.asp

Sub Main()

Dim Locator As WbemScripting.SWbemLocator
Dim Service As WbemScripting.SWbemServices
Dim APCollection As WbemScripting.SWbemObjectSet

If Recycleap.My.Application.CommandLineArgs.Count = 0 Then
Console.WriteLine("Syntax: recycleap server [AppPoolName]")
Console.WriteLine()
Console.WriteLine("Example: recycleap servername DefaultAppPool")
End
Else
strServer = Recycleap.My.Application.CommandLineArgs(0)
If Recycleap.My.Application.CommandLineArgs.Count > 1 Then
strAppPoolName = Recycleap.My.Application.CommandLineArgs(1)
bRecycleAll = 0
End If
End If

'Connect to the specified server using WMI
Locator = CreateObject("WbemScripting.SWbemLocator")
Locator.Security_.AuthenticationLevel = 6
Service = Locator.connectserver(strServer, "root/MicrosoftIISv2")

'Get a collection of WMI apppools
APCollection = Service.InstancesOf("IISApplicationPool")

If bRecycleAll = 1 Then
'Recycle each apppool returned in the collection with a delay of
iRecycleDelay
For Each APInstance As Object In APCollection

Console.WriteLine("Recycling " & strServer & "/" & APInstance.Name)
APInstance.Recycle()

Console.WriteLine("Waiting " & iRecycleDelay & " seconds...")
Threading.Thread.Sleep(iRecycleDelay * 1000)
Next
Else
'If we're not recycling all apppools find the one that was specified
and recycle it
For Each APInstance As WbemScripting.SWbemObject In APCollection
If UCase(APInstance.Name) = UCase("W3SVC/AppPools/" &
strAppPoolName) Then
Console.WriteLine("Recycling " & strServer & "/" &
APInstance.Name)
APInstance.Recycle()
End If
Next
End If

Console.WriteLine("Done!")
Console.Beep()
Console.WriteLine("Press Enter to Close.")

Console.ReadLine()
End Sub

End Module
"Lou Civitella" <lo*@webersystems.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I have found code that Recycles the Application Pool but it was written in
VBScript can anyone convert this for me to VB.Net?
Thanks!

'Appendix B: Application Pool Recycle script - Save as Recycleap.vbs

'By Default Recycle All App Pools
bRecycleAll = 1
'Delay between each apppool recycle in seconds (if all apppools are being
recycled)
iRecycleDelay = 5

If Wscript.arguments.count = 0 Then
WScript.Echo "Syntax: recycleap server [AppPoolName]"
WScript.Echo
WScript.Echo "Example: recycleap servername DefaultAppPool"
WScript.Quit (0)
Else
strServer = WScript.arguments(0)
If WScript.arguments.count > 1 Then
strAppPoolName = WScript.arguments(1)
bRecycleAll = 0
End If
End If

'Connect to the specified server using WMI
set Locator = CreateObject("WbemScripting.SWbemLocator")
Locator.Security_.AuthenticationLevel = 6
set Service = locator.connectserver(strServer,"root/MicrosoftIISv2")

'Get a collection of WMI apppools
set APCollection = Service.InstancesOf("IISApplicationPool")

If bRecycleAll = 1 Then
'Recycle each apppool returned in the collection with a delay of
iRecycleDelay
For each APInstance in APCollection

WScript.Echo "Recycling " & strServer & "/" & APInstance.Name
APInstance.Recycle

WScript.Echo "Waiting " & iRecycleDelay & " seconds..."
Wscript.Sleep(iRecycleDelay*1000)
Next
Else
'If we're not recycling all apppools find the one that was specified
and recycle it
For each APInstance in APCollection
If UCase(ApInstance.Name) = UCase("W3SVC/AppPools/" &
strAppPoolName) Then
WScript.Echo "Recycling " & strServer & "/" & APInstance.Name
APInstance.Recycle
End If
Next
End If

WScript.Echo "Done!"

May 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Stemper | last post by:
I'm looking for some good articles or hints on accessing a .Net component that I've written from old ASP/VBScript. I've gotten as far as referencing the typelib in the global.asa file but when I...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
2
by: ChucRock | last post by:
Hi, I have the following code where there is some client side VBScript that does something and needs to pass a variable back to the ASP.NET page. When the page is updated through a postback, the...
7
by: Ish2000 | last post by:
Hello, I've a simple windows application and i want to be able to convert a csv file to xml. So far, i can browse for the csv file from the file structure and display in a textbox. I want to...
1
by: blaneyj | last post by:
HELP! What I've got going here is: a)Access database (mdb) b)VBScript from ArcGIS (modelbuilder) that processes said Access database to custom Personal GeoDatabase (PGD) I want that Access...
10
by: thinktwice | last post by:
in my script file , i need call a method of a atl com module(implemented in vc++), which returan an safearray. i don't know how to convert it into array in jscript. i have tried serveral ways to...
0
by: neon123 | last post by:
i am using a sql loader to load data into oracle 8. i am using vbscript to run the sql loader. i need to pass username and password entered through vbscript ,,into the visual basic application . ...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
13
by: =?Utf-8?B?Umljaw==?= | last post by:
I have a vbs file (WScript) that I need to convert to vb.net; is there any tools available for that?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.