Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi there,
how to translate this from VBS to C# .NET 2.0 ?

On Error Resume Next
Dim colItems

If WScript.Arguments.Count <> 2 Then
    WScript.Echo "SetConfig.vbs [setting] [value]"
    WScript.Quit
End If

strRequest = WScript.Arguments(0) + "," + WScript.Arguments(1) + ";"

strComputer = "LOCALHOST"     ' Change as needed.
Set objWMIService = GetObject("WinMgmts:" _
    &"{ImpersonationLevel=Impersonate}!\\" & strComputer & "\root\wmi")
Set colItems = objWMIService.ExecQuery("Select * from Lenovo_SetBiosSetting")

For Each objItem in colItems
    ObjItem.SetBiosSetting strRequest, strReturn
Next

WScript.Echo strRequest
WScript.Echo " SetBiosSetting: " + strReturn

If strReturn <> "Success" Then
    WScript.Quit
End If

Set colItems = objWMIService.ExecQuery("Select * from Lenovo_SaveBiosSettings")

strReturn = "error"
For Each objItem in colItems
    ObjItem.SaveBiosSettings ";", strReturn
Next

WScript.Echo strRequest
WScript.Echo " SaveBiosSettings: " + strReturn
Posted
Comments
Sergey Alexandrovich Kryukov 16-Feb-11 22:21pm    
What's you problem? It it's "give me code", please understand that nobody will be interested in this boring stuff (free of charge, by the way). I fear to say, you need to learn both languages and then get your hands dirty, nothing else can help. If you do it and face problems -- welcome back.
--SA
Sandeep Mewara 17-Feb-11 0:33am    
OP replied you via an answer to question.
Sandeep Mewara 17-Feb-11 0:34am    
Hi SAKryukov,

you are of course right, so lets do it shorter:
<pre>
For Each objItem in colItems
ObjItem.SetBiosSetting strRequest, strReturn
Next

WScript.Echo strRequest
WScript.Echo " SetBiosSetting: " + strReturn
</pre>
So do you able to help just with this short code? I have no prob to deal with rest.

Thanks,
Martin
Sunasara Imdadhusen 17-Feb-11 1:09am    
Did you try before?

Here is the tool feature

From:

* C#
* VB.NET
To:
* C#
* Python
* Ruby

Convert VB.NET to C# [^]

Thanks,
Imdadhusen
 
Share this answer
 
Hope vbconversions.net[^]and convert[^]will help you.
 
Share this answer
 
v2
'Libreria : archivos
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Permite manejar archivos.
'
'Dependencia: <ninguna>


'Constantes de funciones/metodos de manejo de archivos
Private Const ForReading = 1
Private Const TristateFalse = 0
Private Const TristateTrue = -1


'Funcion : fileGetFileName
'Parametros : string con FullPathName de un archivo/directorio
'Retorno : string con FileName
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Obtiene el FileName, es decir, la ultima componente de FullPathName dado.
'
Function fileGetFileName( a_pathName )

'Crea objeto filesystem
Dim objFileSystem
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Retorna el filename del path dado
fileGetFileName = objFileSystem.GetFileName( a_pathName )

'Elimina objeto
Set objFileSystem = Nothing

End Function


'Funcion : fileGetFullFilePath
'Parametros : string con FullPathName de un archivo/directorio
'Retorno : string con FilePath
'Por : Jose Antonio Rojas V.
'Fecha : 17/05/2001
'Descripcion: Obtiene el FilePath completo, es decir, el FullPathName dado sin el FileName.
' A partir de "C:\directorio1\directorio2\directorio3\archivo.txt"
' retorna "C:\directorio1\directorio2\directorio3\".
'
Function fileGetFullFilePath( a_pathName )

'Si el parametro dado ya es un filepath, lo retorna
If Right( a_pathName, 1 ) = "\" Then
fileGetFullFilePath = a_pathName
Exit Function
End If

'Crea objeto filesystem
Dim objFileSystem
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Obtiene el filename del pathname dado
Dim filename
filename = objFileSystem.GetFileName( a_pathName )

'Extrae el filepath del pathname dado
fileGetFullFilePath = Left( a_pathName, Len( a_pathName ) - Len( filename ) )

'Elimina objeto
Set objFileSystem = Nothing

End Function


'Funcion : fileGetFilePath
'Parametros : string con FullPathName de un archivo/directorio
'Retorno : string con FilePath
'Por : Jose Antonio Rojas V.
'Fecha : 17/05/2001
'Descripcion: Obtiene el FilePath, es decir, el FullPathName dado sin el FileName
' ni el Drive o unidad de red.
' A partir de "C:\directorio1\directorio2\directorio3\archivo.txt"
' retorna "\directorio1\directorio2\directorio3\".
'
Function fileGetFilePath( a_pathName )

'Recupera fullFilePath
Dim fullFilePath
fullFilePath = fileGetFullFilePath( a_pathName )

'Si viene drive lo elimina
If Mid( fullFilePath, 2, 1 ) = ":" Then fullFilePath = Mid( fullFilePath, 3 )

'Si viene unidad de red la eliminar
If Mid( fullFilePath, 1, 2 ) = "\\" Then

'Busca 1er "\" despues del servidor
Dim pos
pos = InStr( 3, fullFilePath, "\" )

'Si lo encuentra, y asi debiera ser siempre, reasigna filepath a partir de ahi
If pos <> 0 Then fullFilePath = Mid( fullFilePath, pos )

End If

'Retorna
fileGetFilePath = fullFilePath

End Function


'Funcion : fileSaveFileAbsolute
'Parametros : string con FullPathName de un archivo/directorio
' string con datos a grabar
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Graba los datos en archivo dado.
'
Sub fileSaveFileAbsolute( a_absFileName, a_strData )
Call fileSaveFile( a_absFileName, a_strData )
End Sub


'Funcion : fileSaveFileVirtual
'Parametros : string con FullPathName virtual de un archivo/directorio
' string con datos a grabar
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Graba los datos en archivo dado.
'
Sub fileSaveFileVirtual( a_virtualFileName, a_strData )
Call fileSaveFile( a_virtualFileName, a_strData )
End Sub


'Funcion : fileDeleteFileVirtual
'Parametros : string con FullPathName virtual de un archivo
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Elimina el archivo dado.
'
Sub fileDeleteFileVirtual( a_virtualPathName )
Call fileDeleteFile( Server.MapPath( a_virtualPathName ) )
End Sub


'Funcion : fileDeleteFileAbsolute
'Parametros : string con FullPathName de un archivo
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Elimina el archivo dado.
'
Sub fileDeleteFileAbsolute( a_absPathName )
Call fileDeleteFile( a_absPathName )
End Sub


'Funcion : fileReadFileVirtual
'Parametros : string con FullPathName virtual de un archivo
'Retorno : string
'Por : Jose Antonio Rojas V.
'Fecha : 29/01/2001
'Descripcion: Retorna el contenido del archivo dado.
'
Function fileReadFileVirtual( a_virtualPathName )
fileReadFileVirtual = fileReadFile( MapPath( a_virtualPathName ) )
End Function


'Funcion : fileReadFileAbsolute
'Parametros : string con FullPathName de un archivo
'Retorno : string
'Por : Jose Antonio Rojas V.
'Fecha : 29/01/2001
'Descripcion: Retorna el contenido del archivo dado.
'
Function fileReadFileAbsolute( a_absPathName )
fileReadFileAbsolute = fileReadFile( a_absPathName )
End Function


'----------------------------
'Funciones privadas
'----------------------------

'Funcion : fileCreaDirectorio
'Parametros : string con FullPathName de un archivo/directorio
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 15/01/2001
'Descripcion: Crea todos los directorios "arriba" del pathname dado
Private Sub fileCreaDirectorio( a_fileSystem, a_pathName )

'Recupera directorio base del path dado
Dim baseDirectory
baseDirectory = a_fileSystem.GetParentFolderName( a_pathName )

'Si directorio existe retorna
If a_fileSystem.FolderExists( baseDirectory ) Then Exit Sub

'Crea directorios padres y actual
Call fileCreaDirectorio( a_fileSystem, baseDirectory )
Call a_fileSystem.CreateFolder( baseDirectory )

End Sub


'Funcion : fileSaveFile
'Parametros : string con FullPathName absoluto del archivo a crear/actualizar
' string con datos a grabar
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Graba los datos en el archivo dado. Para esto primero crea el
' archivo, si ya existia lo reemplaza.
'
Private Sub fileSaveFile( a_absFileName, a_data )

'Crea objeto filesystem
Dim objFileSystem
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Crea directorio
Call fileCreaDirectorio( objFileSystem, a_absFileName )

'Crea archivo
Dim objFile
Set objFile = objFileSystem.CreateTextFile( a_absFileName, True, False )

'Graba datos
Call objFile.Write( a_data )

'Cierra archivo
Call objFile.Close()

'Elimina objetos
Set objFile = Nothing
Set objFileSystem = Nothing

End Sub


'Funcion : fileDeleteFile
'Parametros : string con FullPathName absoluto de un archivo
'Retorno : <nada>
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Elimina el archivo dado.
'
Private Sub fileDeleteFile( a_pathName )

'Crea objeto filesystem
Dim objFileSystem
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Si existe...
If objFileSystem.FileExists( a_pathName ) Then

'Recupera archivo dado
Dim objFile
Set objFile = objFileSystem.GetFile( a_pathName )

'Lo borra
Call objFile.Delete( True )

'Elimina objeto
Set objFile = Nothing

End If

'Elimina objetos
Set objFileSystem = Nothing

End Sub


'Funcion : fileReadFile
'Parametros : string con FullPathName absoluto de un archivo
'Retorno : string binario
'Por : Jose Antonio Rojas V.
'Fecha : 11/01/2001
'Descripcion: Retorna el contenido del archivo dado
'
Private Function fileReadFile( a_pathName )

'Crea objeto filesystem
Dim objFileSystem
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Recupera el archivo dado
Dim objFile
Set objFile = objFileSystem.GetFile( a_pathName )

'Lo abre para lectura y en modo ASCII (texto)
Dim objFileText
Set objFileText = objFile.OpenAsTextStream( ForReading, TristateFalse )

'Lo lee completo
fileReadFile = objFileText.Read( objFile.Size )

'Cierra archivo
Call objFileText.Close()

'Elimina objetos
Set objFileText = Nothing
Set objFile = Nothing
Set objFileSystem = Nothing

End Function


'Funcion : fileEliminaCarpeta
'Descripcion: Elimina la carpeta. Antes saca el ultimo caracter si era un "\".
' a_fileSystem : Objeto FileSystemObject
' a_pathName : Path absoluto de la carpeta
'Retorno : <nada>
'Por : Claudio Rivas
'Fecha : 26/09/2005
Private Sub fileEliminaCarpeta(a_fileSystem, a_pathCarpeta)
'Elimina ultimo "\" ya que no se encuentra la ruta cuando éste existe
If Right(a_pathCarpeta, 1) = "\" Then a_pathCarpeta = Left(a_pathCarpeta, Len(a_pathCarpeta) - 1)
'Elimina Carpeta
If a_fileSystem.FolderExists(a_pathCarpeta) Then Call a_fileSystem.DeleteFolder( a_pathCarpeta )
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900