.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

passing result from CS file to batch file?

Posted By:      Posted Date: September 09, 2010    Points: 0   Category :.NET Framework
Hello,I am trying to run a CS file within a batch file but so far nothing happens.. echo on cd \ net use z: \\CONFIGMGRTEST\SMSPKGC$\TST00014 rem FFCS-MultiPlatform.bat file rem a selection is made to know which program has to be launched rem SETTING THE LOCATION OF THE C# COMPILER SET framework=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727 rem COMPILING THE CS FILE %framework%\csc Architecture-Processor.cs rem EXECUTING THE C# APPLICATION :32BIT C:\Source Files\Packages\FOREFRONT\x86\FFCS.bat goto END :64BIT C:\Source Files\Packages\FOREFRONT\x64\FFCS.bat goto END :END exit and the CS file is: using System; using System.Management; public class ManagementObject { public static void Main() { /// ManagementObject mo; mo = new ManagementObject("Win32_Processor.AddressWidth='"); ushort i = (ushort)mo["Architecture"]; /// Test the Processor and populated the field to be tested in the batch file switch (i) { case 0: return "32 Bit"; break; case 9: return "64 Bit"; break; } } } How do I pass the 32 Bit and/or 64 Bit collected by the CS file to the batch file to be used to the if .... goto 32Bit or 64 BitsThanks,DomSystem Center Operations Manager 2007 / System C

View Complete Post

More Related Resource Links

Passing Argument from Execute Process Task (SSIS) to a Batch File



I have a batch process set up, which executes fine as long as the name of the file is built in.  My Execute Process task in SSIS also runs this batch file with succes.

I would like to pass the name of the file as a parameter from the Task (SSIS) to this batch file.  Looks like I am doing something wrong because it is failing.

This is the batch file:
cd \Program Files\WS_FTP Pro\
wsftppro -s "local:D:\Folder1\Folder2\%1" -d HDMS:/To_HDMS/

---  The %1 is the parameter

The argument that I am passing in is in the 'StandardInputVariable'

Would really really appreciate some help!  Thanks so much!


file not passing to controller


 I am getting an null referance on file, what am I doing wrong. 

<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
<%: Html.ValidationSummary(true) %>
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
    <input type="submit" name="btnAdd" value="Add" />
<% Html.EndForm(); %>

controller code:

        public ActionResult AddMedia(Guid id, HttpPostedFileBase file, FormCollection collection)
            string mimeType = file.ContentType; //  Null Exception here ..

Run a batch file at server side

Hello,         I am creating an intranet application which runs a batch file and create an xml file as result. Which i am using for further processing. My problem is when i am running my application from local machine batch file is running fine and creating xml,but when i am running it through iis nohting is happening,it meance process.start coudn't start command Prompt.I am using following code. I have given all permission to iis.Dim ProcessInfo As Diagnostics.ProcessStartInfoProcessInfo = New Diagnostics.ProcessStartInfo("cmd.exe", "/C " + Server.MapPath("~\myScript.bat"))        Dim Process As New Diagnostics.Process       ProcessInfo.CreateNoWindow = False        ProcessInfo.UseShellExecute = False        Process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal        Process = Diagnostics.Process.Start(Server.MapPath("~\Spandata\RunSpan.exe"))       Process.WaitForExit(20000)        Process.Close()

Batch file for use with SSIS

Greetings all, I'm trying to run the following batch file outside of SSIS.     DTEXEC /f "M:\Tim\SSIS\ImprtInvestOneNAVsGeneric.dtsx" /conf "M:\Tim\SSIS\EPIC.dtsConfig"      \Package.Variables[User::FilePath].Value;"M:\Tim\SSIS" /SET      \Package.Variables[User::SourceFileName].Value;"DIREXION_NAV.CSV" /SET         \Package.Variables[User::DoneFileName].Value;"BIAUSC50.DONE" /SET      \Package.Variables[User::SponsorID].Value;"56" /SET      \Package.Variables[User::FileDescription].Value;"Direxion NAVs (USA)" /SET      \Package.Variables[User::DBConn].Value;"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=M:\Tim\New             Basket DB\EPICUDT_Development.mdb;User Id=admin;Password=;" /SET  The purpose of this batch file is to allow our team to use the same SSIS package but with multiple file inputs. I am getting the following errors:   - Requires a higher level edition.  I've done some research on this and have found that you must have SSIS installed locallly (which I         do, the services indeed running).  I've also come across a 'fix' that says you can use the E

run dtexec on server from batch file on client machine

Hi I would like to enable a user to execute an SSIS (2005) package located on a server.  The client does not have any elements of SQL server installed on his machine so he cannot execute the package locally.  At present he has to remote connect to the server and double click a batch file on the server that contains the dtexec script. I would like to have a batch file located on the client desktop that he can click, that will run the dtsexec script on the server - as it will not work from the client machine.  However every set of commands i try inevitably end up trying to run the package on the local machine, which obviously fails. Is there any way to have the client kick of the package and have it run on the server, without him actually having to directly remote desktop to the client? Thanks  Guy

Excecuting sql batch file

I created a batch file to set db's online, that will be used after a server reboot in the event 1 or multiple db's do not come back online, my question is... I created this batch file in sql server 2005, and it will not work in sql 2000 or 2003, could I have done something wrong? Or is the issue that batch files are not backwards compatible? Thank you

Need help running sql as batch file that creates a list of borrowers


Our application database was recently upgraded from mssql server 2000 to 2008.  I am unable to get a batch file that creates a list of updated
borrowers to run.  It was running fine on Windows server 2000 (even after the upgrade to mssql 2008), but I
recently wiped that old server and installed windows server 2003.  The
drive that the file lives on changed, so I changed the name in the
file, but it will not run.  When I try to run it from a command prompt
I get the error:

'melcat_daily_borr_export.bat' is not recognized as an internal or
external command, operable program or batch file.

The text of the file is :
isql -S192.168.36.2 -Pmypassword -Umyusername
-iD:\Horizon\melcat\melcat_daily_borr_export.txt -b -h-1 -n -w800 -O

I have tried running the command with the name in quotes, I have
changed the file to a .cmd rather than a .bat, all to no avail.  The
sql that the file calls will run and return results.  Yes I am using
my proper user name and password.

The text of the sql called is this:

use horizon

set nocount on



How to run a batch file with IIS and ASP.NET?



Apologies if my question is too broad but I eed pointers on how to tackle the following problem. Currently, I run a batch file that launches a series of automation tests on QTP (a test automation tool). The batch file contains a vbs script path and it takes three parameters. Each time smeone needs to run the automation, I have to do this manually.
What I'd like to be able to do is to allow other members of the team to access this functionality via an intranet web page. They would be able to login, choose the tests to run and then run them. My only other requirement is that the solution be based on .net and C# if possible. My current server is 2003 SP2.
What is the best way to achiveve what I want?
What is the recommended version of IIS and .NET framework to use?
How do I configure IIS to be able to run the vbs script?
I'm looking for a step-by-step approach if possible. I don't care if I have to convert the batch file into an executable or run the script directly, just as long as it is launched.
Thanks so much for your time.

Open a Batch File in Sql Store Procedure



I have to open a batch file automatically in sql. So i have used the below command.

EXECUTE master.dbo.xp_cmdshell 'D:\Databases\batch\123.bat'

Its worked for few times. After that its not working.

One time i have stopped before the process is complete.May be this is the issue.

Now its returns null value.

Can anyone help me how can i open the file in sql.

Thanks & Regards,


How to create a batch file using a stored procedure



Please let me know how to create a batch file with some content in it, using a stored procedure in SQL 2000.

Thanks in advance.



Calling remote batch file using Execute Process Task



The requiement is to create excel file. I cannot run this code using SSIS vbscript task because this requires Microsoft.Office.Interop DLL which can not be installed on the dev / prod server. Hence using the SQL task the data exported to excel.

But now the excel is required to be updated to merge some cells. The approach we are thinking is to keep VBS file with required code to UNC path. Keep the BAT file running VBS file using CSCRIPT command in same location. Call the BAT file from SSIS package using Execute Process Task. This approach is tested in local system and also works on dev server. But somehow the sample code used to create excel is not creating excel to UNC path.

VBS code below

Const xlSaveChanges = 1
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.Cells(1, 1).Value ="Test value"

The BAT used to call above VBS file is given below

cscript \\server.com\folder$\Demo\Excelfile.vbs

The above UNC path is used in execute process task package which runs fine. But the file is not yet created.


Creating Batch file to execute sql scripts


Hi friends,  


      i want to create batch file to execute all my .sql scripts.

I have all table ( all table scripts in single file ) ,Udds ( all udds in single file ) ,Stored procedures( separate file for each SPs ),Functions ( Separate file for each Functions ),Triggers and views scripts in .SQL file.   

can anybody tell me how to create batch file for executing all these scripts in sql server ?.   

   while executing, it should ask Database name,server name, password. if these details are given then it should execute my all scripts in given database

, if any error thrown then that error and procedure name alone have to move to separate log file..



Please help me if this possible or any other easy way to do this..



Thanks - Ravi

Custom File Stream Result error when the client connection is closed


I recently notice that on our MVC 2.0 web app that does images retrieval,  we have this error when the user close the browser before image file is done transmitting :

TypeName: System.Web.HttpException

TypeAssembly: System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Message: The remote host closed the connection. The error code is 0x80070057.

Source: System.Web

TargetSite: Void RaiseCommunicationError(Int32, Boolean)

StackTrace:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)

   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()

   at System.Web.HttpResponse.Flush(Boolean finalFlush)

   at System.Web.HttpResponse.End()

   at CT.iMagio2.Apps.Web.Search.Controllers.ControllerActionResultInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)

   at System.Web.Mvc.ControllerActionInvoker

How to call C# dll from a batch file?


Hi All,

    As per the requirement I have written a C# code to access Active Directory and to fetch required data and to store it in a database. But this has to be scheduled everyday at the specific time. So I thought to create a batch file which can scheduled as well, but I stuck up with a question that can we call C# dll from a batch file? If we can how to achieve it? Please suggests me if anybody knows about this!

Cheers, Chetan

Multiple result set to a single text file




I have a stored proc which gives me 5 resultsets.

I want to store these  in a flat file.

all the result set columns are different.

How can i store all these results into a single file in SSIS.??


sample resultset columns::

date  name

date  name   id    value

date  name   id    percentage

date  name  id     totalvalue

date  name  duration




Not able to create scheduled task in windows server 2003 using a batch file



I am working on a .net 1.1 windows forms application. We have windows 2003 service pack 2 as the server operating system which uses IIS 6.0.

We have a report generation section. User submits report from the screen(c# code) to run report on a specified time. This request will create a batch file with the AT command with the time specified by the user. This batch file will create an AT job in scheduled tasks window and this AT job will a call another scheduler. This scheduler will generate the report.

the AT command looks like T 16:32 /INTERACTIVE C:\Inetpub\wwwroot\mywebservices\bin\Schedulers.GenerateReport.exe


This is working fine in all servers except one server which uses windows 2003 standard edition. The problem is like it is not able to create the batch file and subsequently fails to create the AT job.

Is there any permission related issue by which it is not able to create the batch file from code.

Please advice me!!!

Passing File to Web Service


Hello all. I am not extremely familiar with web programming and I have reached the point that I am going to start pulling my hair out on this. Most of my programming is in windows.

History: One of our clients hired a company to handle orders for them and it is now my job to set up a web service that will receive a cXML file from them with the order information in it. I created a web service which resides on a Windows 2003 Server using IIS 6. I created an application to send the file to the web service and my problem now is I keep getting access denied when the web service tries to write the file to the hdd. The web service runs as the default IUSR_computername account with Enable anonymous access checked. In one of my troubleshooting attempts I gave the IUSR_.... account full permissions to the folder that the files are to be saved to and this still resulted in access denied when writing the file. The next step I took was looking on the internet to find out how to pass the credentials to the web service and I failed miserably at that also so my question is how do I pass the credentials to the web service so it can write the file to disc?

Here is the web service code. I am using VB.Net 2008 for the application and used VB.Net 2010 for the web service. (two seperate computers)

Imports System.Web
Imports System.Web.S
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend