Thursday, 22 August 2013

The process cannot access the file

The process cannot access the file

Please have a look at the following code
void InformationWriter::writeContacts(System::String ^phone,
System::String ^email)
{
try
{
//Write the file
StreamWriter ^originalTextWriter = gcnew
StreamWriter("contacts.dat",false);
originalTextWriter->WriteLine(phone);
originalTextWriter->WriteLine(email);
originalTextWriter->Close();
//Encrypt the file
FileStream ^fileWriter = gcnew
FileStream("contacts.dat",FileMode::OpenOrCreate,FileAccess::Write);
DESCryptoServiceProvider ^crypto = gcnew DESCryptoServiceProvider();
crypto->Key = ASCIIEncoding::ASCII->GetBytes("Intru235");
crypto->IV = ASCIIEncoding::ASCII->GetBytes("Intru235");
CryptoStream ^cStream = gcnew
CryptoStream(fileWriter,crypto->CreateEncryptor(),CryptoStreamMode::Write);
//array<System::Byte>^ phoneBytes =
ASCIIEncoding::ASCII->GetBytes(phone);
FileStream ^input = gcnew
FileStream("contacts.dat",FileMode::Open); //Open the file to be
encrypted
int data = 0;
while((data=input->ReadByte()!=-1))
{
cStream->WriteByte((System::Byte)data);
}
input->Close();
cStream->Close();
fileWriter->Close();
System::Windows::Forms::MessageBox::Show("Data Saved");
}
catch (IOException ^e)
{
System::Windows::Forms::MessageBox::Show(e->Message);
}
}
When the following part get executed, I get an error
FileStream ^input = gcnew FileStream("contacts.dat",FileMode::Open);
//Open the file to be encrypted
Below is the error I get

This is the first time I am using CryptoStream and I new to C++/CLI as well.
Please help

Copy vagrant box locally

Copy vagrant box locally

I have a vagrant box running on VirtualBox, and I need to make a copy
(with all its existing config and data), so that I can make changes on it
without affecting the original.
The problem is that my original box came as a file package - the internet
connection where I'm working with is extremely slow so someone else copied
their vagrant and virtualbox folders to my machine. Thus there is no
config.vm.box_url
to use.
How can I accomplish this?

LogOff disconnected users from remote desktop

LogOff disconnected users from remote desktop

Firstly I'm new to this..Excuse me If something might asked here is not
appropriate.
I would like to find out the disconnected users and then make all of them
logOff at once from my windows app.
This is what I have found here
Can anyone say how do I use this and from where ?
Or any other alternative is the best option to do ?
As when I'm trying this way :
ExecuteCommand("TSDISCON 31 /SERVER:myservername /V")
Public Sub ExecuteCommand(ByVal Command As String)
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
ProcessInfo = New ProcessStartInfo("cmd.exe", "/K" & Command)
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = True
Process = Process.Start(ProcessInfo)
End Sub
It gives me an error that session Id 31 is not found and when checked it
is showing me the session id 31 is there in the task manager as you can
see it below.
http://imageshack.us/photo/my-images/443/elhs.png/
Sorry as I'm having low rep I couldnt post images here infact proving a link.

Wednesday, 21 August 2013

Vbscript for error handling in copying zip file

Vbscript for error handling in copying zip file

Please help me out. I want a vbscript program to check whether my zip is
completely copied or not and checks whether i have unzipped the exact zip
file.Any ideas and suggestions?

Netbeans C program return value 2

Netbeans C program return value 2

I just got my Netbeans tools configured,and (finally) it worked :) (I
checked with Hello World). We were shifting so I have had like a 3 month
gap so I though I'd make a calculator rather than some other program like
a palindrome checker and bleh bleh bleh. So here's the code :
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void addition(int,int);
void subtraction(int,int);
void mutiplication(int,int);
void division(int,int);
int main() {
int x,y,choice,redo = 1;
while(redo)
{
printf("\nWelcome to the CalC :D\nPlease make a
choice\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n>");
scanf("%d",&choice);
switch(choice);
{
case '1' :
{
printf("Enter the first number\n>");
scanf("%d",&x);
printf("\nThe second number?\n>");
scanf("%d",&y);
addition(x,y);
}
case '2' :
{
printf("Enter the first number\n>");
scanf("%d",&x);
printf("\nThe number to be subtracted from %d is?\n>",x);
scanf("%d",&y);
subtraction(x,y);
}
case '3' :
{
printf("Enter the first number\n>");
scanf("%d",&x);
printf("\nThe number to be multiplied with %d is?\n>",x);
scanf("%d",&y);
multiplication(x,y);
}
case '4' :
{
printf("Enter the first number\n>");
scanf("%d",&x);
printf("\nThe number to be divided by %d is?\n>",x);
scanf("%d",&y);
division(x,y);
}
}
printf("\nWould you like to make another calculation?\n1.Yes '_'
\n2.No! :p\n>");
scanf("%d",&redo);
}
return (EXIT_SUCCESS);
}
void addition(int x,int y)
{
int sum;
sum = x + y;
printf("\nThe sum of %d and %d is %d\n(Press enter to display the
menu)",x,y,sum);
getch();
}
void subtraction(int x,int y)
{
int difference;
ce;
difference = x - y;
printf("The difference between %d and %d is %d\n(Press enter to
display the menu)",x,y,difference);
getch();
}
void multiplication(int x,int y)
{
int product;
product = x * y;
printf("The product of %d and %d is %d\n(Press enter to display the
menu)",x,y,product);
getch();
}
void division(int x,int y)
{
float quotent;
quotent = (float)x/(float)y;
printf("The quotient of %d and %d is %.2f\n(Press enter to display the
menu)",x,y,quotent);
getch();
}
And this is the error I get :
"/C/MinGW/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS=
.build-conf
make[1]: Entering directory
'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
"c:/MinGW/bin/make.exe" -f nbproject/Makefile-Debug.mk
dist/Debug/MinGW-Windows/calc.exe
make[2]: Entering directory
'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
gcc -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o
build/Debug/MinGW-Windows/main.o main.c
main.c: In function 'main':
main.c:26:5: error: case label not within a switch statement
main.c:34:9: error: case label not within a switch statement
main.c:42:9: error: case label not within a switch statement
main.c:52:9: error: case label not within a switch statement
main.c: In function 'subtraction':
main.c:78:5: error: 'ce' undeclared (first use in this function)
main.c:78:5: note: each undeclared identifier is reported only once for
each function it appears in
main.c: At top level:
main.c:83:6: warning: conflicting types for 'multiplication' [enabled by
default]
main.c:48:13: note: previous implicit declaration of 'multiplication' was
here
nbproject/Makefile-Debug.mk:66: recipe for target
'build/Debug/MinGW-Windows/main.o' failed
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[2]: Leaving directory
'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory
'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 661ms)
I'm used to code::blocks so I don't really know what's the problem here :\
please help me out,I clearly defined the switch labels as '1','2','3','4'!
Thanks guys :)

java.lang.StackOverflowError due to recursion

java.lang.StackOverflowError due to recursion

My problem is that I usually get a java.lang.StackOverflowError when I use
recursion. My question is - why does recursion cause stackoverflow so much
more than loops do, and is there any good way of using recursion to avoid
stack overflow?

Get parameter's value of a Data Annotation

Get parameter's value of a Data Annotation

The goal
Get parameter's value of a Data Annotation.
The problem
I don't know the syntax.
The scenario
There is the following controller on my application:
[PermissionsFilter(Roles = "Administrator")]
public ActionResult Index()
{
return View();
}
And there is the following method on my application:
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return true;
}
What I need seems to be simple: how do I get the Administrator string on
the AuthorizeCore method?
Knowledge spotlight
The AuthorizeCore is within of PermissionFilters class that implements
AuthorizeAttribute. In other words, I'm overriding the AuthorizeCore
method of Authorize attribute to create a new one (PermissionFilters
attribute).